0

I am using ASP.Net MVC 3. My application handles request for domain and sub-domain as well. Cookies works fine for domain level application and user login and validation works fine but for sub-domain it become fails.

I have already tried the domain setting i-e parent domain, machine key setting. Even I started a new empty application for testing, it doesn't worked.

Have tried but still not working.

<authentication mode="Forms">
    <forms enableCrossAppRedirects="true" name=".ASPXAUTH" />
</authentication>

FormsAuthentication.SetAuthCookie("tech", false);

HttpCookie cookie = FormsAuthentication.GetAuthCookie(User.Identity.Name, false);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
// Store roles inside the Forms cookie.  
FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
                                                 ticket.Version, 
                                                 "aspuser",
                                                 ticket.IssueDate, 
                                                 ticket.Expiration, 
                                                 ticket.IsPersistent, 
                                                 String.Join("|", "test"), 
                                                 ticket.CookiePath
                                                 );
cookie.Value = FormsAuthentication.Encrypt(newticket);
cookie.HttpOnly = false;
cookie.Domain = "localhost";
Response.Cookies.Remove(cookie.Name);
Response.AppendCookie(cookie);
tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

The cookie treats the sub domain as a seperate domain. According to this article you can set it to ".mydomain.com". Note the starting period.

http://www.15seconds.com/issue/971108.htm

Kenoyer130
  • 6,874
  • 9
  • 51
  • 73