Forms Authentication across Sub-Domains

When you authenticate the user, set the authentication cookie’s domain to the second-level domain, i.e. parent.com. Each sub-domain will receive the parent domain’s cookies on request, so authentication over each is possible since you will have a shared authentication cookie to work with.

Authentication code:

System.Web.HttpCookie authcookie = System.Web.Security.FormsAuthentication.GetAuthCookie(UserName, False);
authcookie.Domain = "parent.com";
HttpResponse.AppendCookie(authcookie);
HttpResponse.Redirect(System.Web.Security.FormsAuthentication.GetRedirectUrl(UserName, 
                                                                       False));

Leave a Comment