[英]ASPX auth cookie expiration time is always 30 minutes
我已將cookie的到期時間設置為1個月,但是當我在瀏覽器中查看.ASPXAUTH cookie的到期超時時,它表示從現在開始提前30分鍾。
var ticket = new FormsAuthenticationTicket(1, "myname", DateTime.Now,
DateTime.Now.AddMonths(1), true, "test");
string ticketString = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString)
{
Expires = DateTime.Now.AddMonths(1),
Path = FormsAuthentication.FormsCookiePath
};
HttpContext.Current.Response.Cookies.Add(cookie);
你能讓我知道為什么上面的代碼表現如此,我想改變過期時間,但總是要30分鍾。
根據其他答案的建議,我得到了這個鏈接。
顯然,在ASP.NET中,它會檢查Web.config中的過期,並且不會從cookie中過期。 所以你需要添加到<system.web>
里面的配置文件:
<authentication mode="Forms">
<forms
name=".ASPXAUTH"
loginUrl="Login.cshtml" //your login page
defaultUrl="Default.cshtml" //your default page
protection="All" //type of encryption
timeout="43200" //a month in minutes
path="/"
requireSSL="false"
slidingExpiration="true" //Every refresh the expiration time will reset
cookieless="UseDeviceProfile" //Use cookies if the browser supports cookies
domain=""
enableCrossAppRedirects="false">
<credentials passwordFormat="SHA1" />
</forms>
</authentication>
您是否需要以編程方式設置此超時,還是可以在配置文件中設置它? 有一個超時參數,表示身份驗證cookie超時: http : //msdn.microsoft.com/en-us/library/1d3t3c61.aspx
此參數的默認值為30分鍾。
最好的問候,德米特里
檢查你的web.config文件,下面的元素system.web - > authentication下應該有FORM條目。
檢查那里的超時屬性,是否設置為30分鍾?
從那里刪除此表單身份驗證標記。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.