This is a really annoying issue and i don't know where to start to look to resolve it.
This issue does not happen when i run the code locally, only when i run it on the live environment. I know i am missing something, and its probably obvious i just can figure it out.
Okay I have an MVC 4 application where i have overridden MembershipProvider. I am pretty sure this is not the issue as the login does work. Login works on IE, Firefox, Safari but fails on Chrome Desktop (Windows 7), and Chrome IOS (on the Ipad).
On Chrome the user is required to log in twice. On the first attempt the ASPXAUTH element of the cookie is not being set. BUT it is set on the second attempt. (Reviewed in Fiddler)
I have looked around and found this suggestion and i have implemented it but i still have the issue. (This does not detail my issue completely but it was close)
http://www.hanselman.com/blog/FormsAuthenticationOnASPNETSitesWithTheGoogleChromeBrowserOnIOS.aspx
(I have 4.5 installed so i knew this was a very long shot)
I have no idea where to start to look to resolve this. Here is the code where i create the cookie.
private void SignIn(string userName, bool RememberMe)
{
MyMembershipProvider provider = (MyMembershipProvider)System.Web.Security.Membership.Provider;
MyMembershipUser user = (MyMembershipUser)provider.GetUser(userName, false);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
user.UserName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
true,
user.UserID.ToString(),
FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
Response.Cookies.Add(authCookie);
}
After the cookie has been created i Redirect
return Redirect("Https://www.sitehome.local");
Please note i am running the whole site under HTTPS in case this is causing the issue
As we figured out in the comments, the cookie was not being forwarded upon redirect and was fixed by creating the cookie in this manner:
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString)
{
Secure = FormsAuthentication.RequireSSL,
Path = FormsAuthentication.FormsCookiePath,
HttpOnly = true,
Domain = FormsAuthentication.CookieDomain
};
Response.Cookies.Add(authCookie);