[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1128
  • Last Modified:

Session duration in ASP.NET

Hi Experts,

1) By default the session duration is 20min, if the user exceeds the time, i want to keep live that session. how?
2) how can we know that user is active or he is idle?
3) How can we extend teh session duration if user is active?

with regards
3 Solutions
You might want to read up about Sessions.

1. You can set the timeout explicitly in the web.config or in your code
2. You can't, since the web is stateless you know the user is active when they do a postback.
3. The session will extend itself. 20 minutes from the last postback received.

This AJAX solution may help you in keeping your session alive

I agree with 1 and 3.

For the second one you can check the IsClientConnected property to check the user connectivity. It is good to use this property in long processes such as sending a file to client.


If Response.IsClientConnected=true then
Response.Write("The user is still connected!")
Response.Write("The user is not connected!")
end if

Like everyone said, you dont really know if a user left your page or left his browser open to the page or turned the browser off, only that he was active in the last somany minutes.

of course you could include some code in anyscreen that kept the session active via some mechanism... ajax or even a hidden frame or iframe with a single line that did a meta refresh every minute or so. (make sure its a .aspx page not a html page, that wont keep the session alive)

You can persist the user data forever if you want by changing the session state to be stored in a DB instead of in memory.
webconfig stuff...
<sessionState   mode="SQLServer"  sqlConnectionString="data source=server;user id=uid;password=pwd"  />
.net has the tools to create the sql db.
Split 4 ways. Everyone gave a possible solution

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now