下面是我在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