Pergunta

I am not sure how that forms authentication. But I assume it just creates cookie based on forms authentication timeout.

So given that I am trying to increase forms auth cookie expiration based on some headers sent to server. For that I disabled slidingExpiration in order to calculate expiration on my own.

In Application_BeginRequest I am doing:

if (!bypassSlidingExpiration)
{
    var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
    authCookie.Expires = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes);
    Response.Cookies.Add(authCookie);
}

But regardless of bypassSlidingExpiration my session expired after FormsAuthentication.Timeout.

What I am going wrong here?

Nenhuma solução correta

Outras dicas

What are you doing the other code branch? It looks like you're only handling the case where bypassSlidingExpiration is false. If bypassSlidingExpiration is true, then you're taking the default value (30 minutes, or whatever's specified in the web.config or programmatically).

You could consider using FormsAuthentication.SetAuthCookie(username, true) to bypass the sliding expiration. The second parameter is whether the cookie should be persistent. It's probably best to avoid manipulating the cookie manually. If you for some reason you must, something like this might work:

if (bypassSlidingExpiration)
{
    var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
    authCookie.Expires = DateTime.MaxValue;
    Response.Cookies.Add(authCookie);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top