Wednesday, November 16, 2005

Unit Testing ASP.NET 2.0 Forms Auth Site

I may have missed a simpler solution, but when trying to run a simple unit test against an Asp.net website that had forms authentication enabled, I needed this entry in the web.config:

<location path="VSEnterpriseHelper.axd">
<system.web>
<authorization>
<allow users="?">
</allow>
</authorization>
</system.web>
</location>

Otherwise, you end up with an error such as:

"The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost/SimpleTestWebsite/VSEnterpriseHelper.axd' returned an error: The information returned is invalid. "

I would have figured this would be covered in documentation, but couldn't find it there. I also would have thought that logging in via FormsAuthentication.Authenticate("user","pass") in one of the test setup methods would have helped. Apparently, this call is made though before you even setup the test fixture. If I were the MS developer behind this my face would be awfully red.
Submit this story to DotNetKicks

No comments: