asp.net mvc - How to extend AuthCookie expiration time when page refresh is refreshed? -
i set authcookie in login action method this
formsauthentication.setauthcookie(username,true);
and in global.asax file put refresh code, (this executed after each action method authentication)
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); }
but it's not working , log out after small period of time, although when check cookie through browser settings, expiration time set correctly.
probably there value set timeout of logged user/session in web.config', this:
<authentication mode="forms"> <forms loginurl="~/user/login" timeout="10" /> </authentication>
you useful info forms sessions here: forms authentication timeout vs sessionstate timeout
Comments
Post a Comment