.Text 支持二级域名之二
做了.Text的二级域名后,一直没有时间好好测试,今天下午发现在subdomain.domain.ext下登录和在www.domain.ext下登录的信息不能共用,这个原因很明了,那就是两个域名下用System.Web.Security.FormsAuthentication.SetAuthCookie方法写入的Cookie的Domain是包涵二级域名的,这就造成了不同的二级域名下的登录信息会在客户端产生不同的Cookie文件。
找到原因后,在SetAuthCookie方法加上几句
HttpCookie cookie = HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName];
cookie.Domain = ".Domain.Ext";
HttpContext.Current.Response.Cookies.Add(cookie);
这下可以不同二级域名可以共用Cookie了,可是后来又发现一个问题,点注销没有反应!!
那再对SignOut做点手脚
System.Web.Security.FormsAuthentication.SignOut();
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,"");
cookie.Expires = new DateTime(1999,10,12);
cookie.Domain = Util.UrlHelper.GetDomain();
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Secure = FormsAuthentication.RequireSSL;
Response.Cookies.Add(cookie);
Response.Redirect(Config.CurrentBlog(Context).FullyQualifiedUrl);
找到原因后,在SetAuthCookie方法加上几句
HttpCookie cookie = HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName];
cookie.Domain = ".Domain.Ext";
HttpContext.Current.Response.Cookies.Add(cookie);
这下可以不同二级域名可以共用Cookie了,可是后来又发现一个问题,点注销没有反应!!
那再对SignOut做点手脚
System.Web.Security.FormsAuthentication.SignOut();
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,"");
cookie.Expires = new DateTime(1999,10,12);
cookie.Domain = Util.UrlHelper.GetDomain();
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Secure = FormsAuthentication.RequireSSL;
Response.Cookies.Add(cookie);
Response.Redirect(Config.CurrentBlog(Context).FullyQualifiedUrl);