下面是我在web.config中的身份驗證配置:如何設置ASP.NET_SessionId cookie的到期日期?
<authentication mode="Forms">
<forms loginUrl="~/Account/Sigin"
name="MYCAUTH"
timeout="3000" />
</authentication>
我怎樣才能使雙方MYCAUTH
和ASP.NET_SessionId
餅乾使用過期?
下面是我在web.config中的身份驗證配置:如何設置ASP.NET_SessionId cookie的到期日期?
<authentication mode="Forms">
<forms loginUrl="~/Account/Sigin"
name="MYCAUTH"
timeout="3000" />
</authentication>
我怎樣才能使雙方MYCAUTH
和ASP.NET_SessionId
餅乾使用過期?
試試這個:
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);
var myCookie = Request.Cookies["myCookie"];
if (myCookie != null)
{
HttpCookie respCookie = new HttpCookie("myCookie", "MyValue");
respCookie.Expires = DateTime.Now.AddMinutes(5);
Response.Cookies.Set(myCookie);
}
的可能重複http://stackoverflow.com/questions/10439483/set-update-expiration-on-aspxauth-and-asp-net-sessionid-cookies ? – TheFallenOne
@The_Outsider不回答 – JamesL