二級功能變數名稱之間共用Cookie,很重要的一點就是配置,如下: domain設置為.ahdqxx.com,如果你的功能變數名稱是www.ahdqxx.com,mall.ahdqxx.com,那麼請設置你的domain為.ahdqxx.com path設置為/ <authentication mode="Form ...
二級功能變數名稱之間共用Cookie,很重要的一點就是配置,如下:
domain設置為.ahdqxx.com,如果你的功能變數名稱是www.ahdqxx.com,mall.ahdqxx.com,那麼請設置你的domain為.ahdqxx.com
path設置為/
<authentication mode="Forms">
<forms name="DQ.AUTH" loginUrl="http://www.ahdqxx.com/Login/Index" protection="All" domain=".ahdqxx.com" timeout="43200" path="/" requireSSL="false" slidingExpiration="true" />
</authentication>
第二重點的就是登陸時候Cookie設置,
不要忘記使用之前配置的東西來設置 Cookie(FormsAuthentication.FormsCookiePath,FormsAuthentication.CookieDomain)
public virtual void SignIn(Customer customer, bool createPersistentCookie) { var now = DateTime.UtcNow.ToLocalTime(); var userdata = JsonConvert.SerializeObject(new SimpleUser { Name = _customerSettings.UsernamesEnabled ? customer.Username : customer.Email, ID = customer.CustomerGuid }); var ticket = new FormsAuthenticationTicket( 1 /*version*/, _customerSettings.UsernamesEnabled ? customer.Username : customer.Email, now, now.Add(_expirationTimeSpan), createPersistentCookie, userdata, FormsAuthentication.FormsCookiePath); var encryptedTicket = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); cookie.HttpOnly = true; if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } cookie.Secure = FormsAuthentication.RequireSSL; cookie.Path = FormsAuthentication.FormsCookiePath; if (FormsAuthentication.CookieDomain != null) { cookie.Domain = FormsAuthentication.CookieDomain; } _httpContext.Response.Cookies.Add(cookie); _cachedCustomer = customer; }
容易犯得的錯誤,如果你在配置中使用了machineKey節點,請保證相關站點使用相同的machineKey