ASPXAUTH cookie重复

时间:2018-05-14 18:06:45

标签: c# asp.net-mvc cookies session-cookies

我正在使用FormsAuthentication.FormsCookieName处理WebApplication。我在WebConfig中有这个:

<httpCookies requireSSL="true" />
<authentication mode="Forms">
    <forms cookieless="UseCookies"
           name=".ASPXAUTH1" />
</authentication>

代码:

var httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket))
{
    HttpOnly = true,
    Domain = "." +host, // Ex- host = google.com (without www because we use subdomains)
    Secure = false

};
httpCookie.Expires = remember ? DateTime.Now.Add(FormsAuthentication.Timeout) : DateTime.Now.AddMinutes(1);

当我登录网络应用程序时,一切看起来都不错:

enter image description here

红色箭头= .google.com

的域名

几秒钟后,第二个Cookie会显示不同的域= www.google.com和过期日期

enter image description here

我没有使用RedirectToLoging Page Method。

1 个答案:

答案 0 :(得分:0)

解决了在webconfig中添加slidingExpiration属性的问题

      <authentication mode="Forms" >
    <forms cookieless="UseCookies" name=".ASPXAUTH"  slidingExpiration="false" />