Team System Developer Center > Visual Studio Team System Forums > Visual Studio Web Performance and Load Testing > forms authentication and log on in tests (Visual Studio 2008)
Ask a questionAsk a question
 

Answerforms authentication and log on in tests (Visual Studio 2008)

  • Wednesday, June 11, 2008 9:43 AMErich Bühler Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi guys,

    I'm using VS 2008 to write some Web Unit Tests and I would like to log on before running them.

    I am using forms authentication but I can't find the way to do it. I would like to log on and off with different users to check different scenarios...

     

    Does anybody know how I can do  this?
    Thanks in advance!!!

    Erich.

Answers

  • Tuesday, June 24, 2008 1:09 AMEd GlasMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Erich, if you are recording the web test using the web test recorder (right click on project -> new web test), you will find the user name and password were recorded as form post parameters.

     

    Find the login request in the web test request tree, and expand the request see the parameters.

     

    However, in the first post you referenced "WebHostAdapter", and your other post you link to is about an ASP.NET unit test. So which is it?

     

    Also, what error are you getting exactly?

     

    Ed.

     

All Replies

  • Friday, June 13, 2008 5:07 AMBill.WangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Erich

     

    Could you tell us why you want to log on before a Unit Test so that we can make a workaround. ASP.NET unit test code run in the same process as the web server such as IIS or ASP.NET Development Server, which means you can directly set the Identity for current user. For example, you can set HttpContext.Current.User.Identity to a specified user to represent that user is logon.

    If I misunderstand you, please let me know.

  • Friday, June 13, 2008 11:59 AMErich Bühler Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Bill,

    thanks for your answer. We have a screen which shows some different options based on the current user, so we need to log a user on before running the tests.

     

    If forms authentication is on (and using the .NET membership Provider), then test infrastructure doesn't work because they can't access to 'WebHostAdapter' or 'VSEnterpriseHelper.axd' processes. We tried adding the following line, but it was fruitless:

     

    <location path="VSEnterpriseHelper.axd">

        <system.web>

          <authorization>

            <allow users="*"></allow>

          </authorization>

        </system.web>

      </location>

     

    One of the errors that we get is the followings one:

     

    The test adapter 'WebHostAdapter' threw an exception while running test 'getAPost'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:2323/AxcoWorld/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error.
    The remote server returned an error: (500) Internal Server Error.

    --------------------------

     

     You can't even run the following line because tests infrastructure fails.

     

     HttpContext.Current.User.Identity

     

    If we run the Web application straightforwards, then everything is fine, so there's no problem there.

     

    Regards,
    Erich.

  • Friday, June 13, 2008 4:57 PMBill.WangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Erich

     

    In your scenario, I think the web test is more suitable than ASP.NET unit test. ASP.NET unit test is mainly used to test code in App_Code folder. To test whether the displayed user name is correct, you can create a web test and set validation/extraction rules. If the displayed result is correct, you can assume the underlying logic is also correct. By web test, there’s no need to programmatically set user identity. What you need to do is record a web test and set the data source containing user credentials to be tested.

     

    You may reference How to Add Data Binding to a Web Request.

     

    If you have to use the ASP.NET unit test in form authentication web application. You have to set the UrlToTest attribute to point to a public that can be accessed without authentication. You can do following steps:

    1. Allow 'VSEnterpriseHelper.axd' to be accessed without authentication as what you have done.
    2. Create a temp aspx page and allow it to be accessed without authentication. For example, I create a Temp.aspx and set the access permission as what you set to 'VSEnterpriseHelper.axd'.
    3. In the test method, set the UrlToTest attribute to point to the Temp.aspx. For example:

            [TestMethod()]
            [HostType("ASP.NET")]
            [AspNetDevelopmentServerHost("%PathToWebRoot%\\TesterWeb", "/TesterWeb")]
            [UrlToTest("http://localhost/TesterWeb/Login.aspx")]
            public void FooTest()
            {
            }

    Then you should be able to run ASP.NET unti test.
  • Monday, June 16, 2008 8:06 AMErich Bühler Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Bill,

    sorry for the misunderstanding but when I mention tests I'm talking to Web Tests only (that's where we find the problems with authentication). So, all this thread is 100% related to ASP.NET Web tests :-).

     

    As I mentioned in my second post, we have allowed 'VSEnterpriseHelper.axd' to be accessed without authentication, etc etc, but nevertheless, we are getting the error we reported (please take a look at the log file included there)

     

    Thanks in advance,
    Erich.

     

  • Monday, June 16, 2008 9:12 AMBill.WangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Erich

    I’m sorry for misunderstanding you. For HTTP 500 error, it’s caused by the web server, not by permission. Could you please try the web test manually to see if the server logic is correct?  Meanwhile, you can also check the event log (Start->Run->eventvwr) to see if there’s some error notice about the web server.

     

  • Monday, June 16, 2008 9:31 AMErich Bühler Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Bill,

    Web site is working fine. Could you please take a look at the information provided in the following post:

     

    http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=3334089&SiteID=1

     

    Thanks in advance,
    Erich.

  • Monday, June 16, 2008 10:32 AMBill.WangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Erich

    Since you are running web test, you can remove the location configuration for VSEnterpriseHelper.axd. It’s my mistake. I checked the event log you’ve posted and I noticed the error 0x800705DE. Would you please try the following?

    1. Clear the event log and run the test again. It’s possible that your event log is full.
    2. Check whether assemblies from old .NET Framework are referenced. If so, change the reference to the latest version.
    3. Try a manual test to see if this error is still logged.  If it’s not logged in manual test, while you were recording web test, please make sure the pages are fully loaded before posted back.

     

  • Monday, June 16, 2008 10:48 AMErich Bühler Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Bill,

    We got the same error,and the log seems to be the same...

     

    Thanks in advance,
    Erich.

  • Monday, June 16, 2008 12:40 PMBill.WangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Would you locate the page that caused this error and check whether some 3rd party controls are used?   If you create a simple web page, does the same thing happen? Meanwhile, is there any Visual Studio Add-in or assembly from .NET Framework 1.0 used? If you disabled all Add-in, does the problem remain?

  • Tuesday, June 24, 2008 1:09 AMEd GlasMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Erich, if you are recording the web test using the web test recorder (right click on project -> new web test), you will find the user name and password were recorded as form post parameters.

     

    Find the login request in the web test request tree, and expand the request see the parameters.

     

    However, in the first post you referenced "WebHostAdapter", and your other post you link to is about an ASP.NET unit test. So which is it?

     

    Also, what error are you getting exactly?

     

    Ed.

     

  • Friday, October 30, 2009 8:55 PMbicycle1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Where is the event log.  Is there a set procedure to clean it out.  I am getting the 0x800705DE event log full error when I try to install IE7.