Reputation: 44155
I am using Visual Studio 2010 SP1 in Windows 7 64bit dev box. My asp.net works fine when using IIS on the box but when I switch to using Visual Studio Development Server, I get an exception "System.Web.HttpException: Unable to validate data" in this line (in Application_AuthenticateRequest event in global.asax.cs):
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
Why does this fail when using the internal web server?
Upvotes: 10
Views: 27187
Reputation: 1
I used @Michiel van Oosterhout's method but it did not work. however, then I added:
<authentication mode="Forms">
<forms protection="Encryption" enableCrossAppRedirects="true"/>
</authentication>
Now it works.
Upvotes: 0
Reputation: 28875
There is another cause of this error. If your MachineKey entry in the Web.config file ends with
xmlns=""
Then you will also suffer this error.
Upvotes: 0
Reputation: 23084
Try deleting your cookies after you switch servers. Both servers have their own configuration and probably their own decryption key with which the forms authentication cookie is encrypted and decrypted. Thus, if you still have the cookie encrypted by IIS, then switch the project to use the built-in development server and hit the site, that server can't decrypt the cookie.
You can prevent this issue if you put the decryption key in your web.config:
<machineKey decryptionKey="..." />
Upvotes: 20