Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolonging asp.net session enddate?

How is asp.net Session prolonging, does every request prolongs the end date of Session, and is it enough to call void() by ajax to extent Session end date by another period of time(default 20 min or so...)

public void ResetSessionTime()
{

}

or do i have to invoke session in some way:

public void ResetSessionTime()
{
    User currentUser = HttpContext.Current.Session[userSessionKey] as User;
}

how does simple request extend session end date?

This question claims every post-back prolongs session...

This MSDN about Session State Providers :

"Each session created by ASP.NET has a timeout value (by default, 20 minutes) associated with it. If no accesses to the session occur within the session timeout, the session is deemed to be expired, and it is no longer valid."

How does request access the session exactly?

THIS QUESTION: Keeping session alive C# does not answer how session end date is prolonged by request, only a opinion on how to keep session alive from client side

EDIT:

According to this article, method needs to be extended from IHttpHandler, in order to access current session...

public class KeepSessionAlive : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Session["KeepSessionAlive"] = DateTime.Now;
    }
}
like image 347
Davor Zubak Avatar asked Jan 28 '13 15:01

Davor Zubak


People also ask

How long do ASP.NET sessions last?

A session automatically ends if a user has not requested or refreshed a page in an application for a specified period of time. This value is 20 minutes by default. You can change the default for an application by setting the Session.

Can you set the session out time manually?

Yes, we can set the session timeout manually in web. config. In ASP.NET we can set the session timeout in the web. config file.

How do I set session timeout to infinite in web config?

The Timeout property can be set in the Web. config file for an application using the timeout attribute of the sessionState configuration element, or you can set the Timeout property value directly using application code. The Timeout property cannot be set to a value greater than 525,600 minutes (1 year).


1 Answers

Every time you make a request, the session timeout is reset. A request can be a page load or something like an ASYNC call.

Take a look at this question for an example of how to keep the session alive by periodically making AJAX calls to the server. (Keeping ASP.NET Session Open / Alive)

like image 149
UnitStack Avatar answered Oct 21 '22 01:10

UnitStack