2017-07-28 6 views
0

ページリフレッシュをリフレッシュするときにAuthCookieの有効期限を延長する方法はありますか?

protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) 
{ 
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; 

HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, true); 
var ticket = FormsAuthentication.Decrypt(cookie.Value); 
var newticket = new FormsAuthenticationTicket(ticket.Version,                  
ticket.Name,ticket.IssueDate,          
ticket.Expiration,true,"new user data",ticket.CookiePath); 

cookie.Value = FormsAuthentication.Encrypt(newticket); 
cookie.Expires = newticket.Expiration.AddHours(24); 
HttpContext.Current.Response.Cookies.Set(cookie); 
} 

(これは、各アクションメソッドの認証後に実行されます)、私はこの

FormsAuthentication.SetAuthCookie(username,true); 

のようなログインアクションメソッドになAuthCookieを設定し、Global.asaxファイルで、私はリフレッシュコードを置きますしかし、それは動作していないと私はブラウザの設定を介してそのクッキーをチェックすると、少しの時間の後にログアウト、有効期限が正しく設定されていた。

<authentication mode="Forms"> 
    <forms loginUrl="~/User/Login" timeout="10" /> 
</authentication> 

あなたがここからフォームセッションに関するいくつかの有用な情報を得ることができます:

答えて

関連する問題