I have an MVC 4 website that uses .NET Framework 4.0 and has been deployed with a Windows Server 2003 IIS and I am having problems with forms authentication on an iPhone (especially Chrome browser).
Scenario
- I Open Chrome app on the iPhone.
- I go to my website and click Login. I manage to successfully log into my website using Forms Authentication.
- I leave the website open for 5 minutes doing nothing.
- I come back to my iPhone and click on a link on my website. I have been logged out.
- I attempt to log in the same way as before. The log in process does not work. No errors, it just takes my to my home page (which is what it is supposed to do on successful login).
Other information
- Generally Safari on the iPhone does NOT seem to suffer from this problem except... after the issue has gone wrong in Chrome it seems to go wrong in Safari also.
- The solution seems to be to clear all my cache/cookies and try again 20 minutes or so later.
- My timeout is actually set to 30 minutes so Chrome should not be experiencing this issue logging out anyway.
I've researched this post (Asp.Net Forms Authentication when using iPhone UIWebView) amongst others and tried:-
(a) The UseCookies setting in the web.config
(b) The .browser configuration file
(c) A MachineKey in the web.config
Nothing seems to make a difference and the Chrome login seems to stay up only for a minute or two.
Code
The code to create the forms authentication cookie is as follows...
FormsAuthentication.Initialize()
Dim fat As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, UserID, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), False, Roles, FormsAuthentication.FormsCookiePath)
Response.Cookies.Add(New HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)))
Any suggestions on how I can resolve this issue?