Thursday, November 13, 2008

Opera browser - Problem with login using asp.net forms authentication cookies

For years I've been getting my ass-kicked with several of my asp.net sites. For reasons that remained unknown to me for several years, whenever I'd try to login to one of these applications from opera, opera would just fail to login.

There would be no error message. You'd type in your user and password, click the login button, the page would refresh, but you'd simply not be logged in.

Finally, I have discovered the cause and a solution to this annoying problem!

I always suspected the problem with Opera was related to the authentication cookie, but I was unable to really figure out why. All I knew was that on my apps that failed Opera wouldn't have an authentication cookie, while on other apps it would get a cookie just fine.

The particular applications where I have been having the problem all share some common unique attributes. They use some kind of URL Rewrting (though not always the same mechanism), they all use the built-in SQL Membership provider (or a customized variation of it), and they are are very complex applications. Most of them host multiple virtual sites within the same physical asp.net app.

I have other applications that work just fine with Opera though. Some of those were also just as advanced as the failing sites and used similar mechanisms.

So for years I've tried and failed to determine a common factor between the failing apps and the working ones.

In none of these cases though have I every had a problem with any other browser, and I generally test sites with 5 or more.

Google has been no help here either. While I find similar reports of this kind of problem, you have to dig very deep and when you do find someone reporting a similar problem there is never a solution offered.

But this week, I finally managed to track down and fix this annoying problem.

It turns out that Opera doesn't correctly handle cookie names that contain spaces.... or at least not when issued via the asp.net authentication system.

In web.config there is a <forms> element within the <authentication> section. This is where you setup details about how the forms authentication system should work. One of the properties is called "name" and this property sets the name of the cookie that will be issued to the browser with the user's authentication ticket. If you omit the name property, asp.net uses a default name of ".ASPXAUTH".

In all of my failing applications, I had manually set a value for the name propery, and that name contained spaces. In fact, most of these apps used the same name because I generally copied this section of configuration from one of the other apps.

Changing the cookie name to one that does not use spaces allows opera to correctly handle the cookie...  login failure solved!

Three years of frustration all because of a space...  but that's programming for ya!



No comments:

Post a Comment