如何设置ASP.NET_SessionId cookie的过期日期?

如何设置ASP.NET_SessionId cookie的过期日期?,asp.net,cookies,session-cookies,Asp.net,Cookies,Session Cookies,以下是如何在web.config中配置身份验证: <authentication mode="Forms"> <forms loginUrl="~/Account/Sigin" name="MYCAUTH" timeout="3000" /> </authentication> 如何使MYCAUTH和ASP.NET\u SessionIdcookies使用过期?尝试以下方法:

以下是如何在web.config中配置身份验证:

<authentication mode="Forms">
      <forms loginUrl="~/Account/Sigin" 
             name="MYCAUTH" 
             timeout="3000"  />
</authentication>


如何使
MYCAUTH
ASP.NET\u SessionId
cookies使用过期?

尝试以下方法:

    var myCookie = Request.Cookies["myCookie"];
    if (myCookie != null)
    {
        HttpCookie respCookie = new HttpCookie("myCookie", "MyValue");
        respCookie.Expires = DateTime.Now.AddMinutes(5);
        Response.Cookies.Set(myCookie);
    }
DateTime expireDate = DateTime.Now.AddDays(30);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, expireDate, true, string.Empty);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
authenticationCookie.Expires = ticket.Expiration;
Response.Cookies.Add(authenticationCookie);
FormsAuthentication.SetAuthCookie(userName, true);

“可能是复制品吗?”没有回答的局外人汉克斯。是否可以使用
FormsAuthentication.SetAuthCookie
?另外请注意,我更新了我的问题。我需要
ASP.NET_SessionId
MYCAUTH
ASP.NET_SessionId
的过期时间将在您关闭浏览器后立即过期。A不管怎样,这两件事是不同的。有关更多信息,请参阅本文