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

x
  • 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
Gopi
0
gbreddy
Asked:
gbreddy
3 Solutions
 
GavinMannionCommented:
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.

0
 
naveenkohliCommented:
This AJAX solution may help you in keeping your session alive

http://www.netomatix.com/Development/SessionLeaseControl.aspx
0
 
barisgomlekCommented:
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.

<html>
<body>

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

</body>
</html>
0
 
HouseMusicCommented:
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.
0
 
GavinMannionCommented:
Split 4 ways. Everyone gave a possible solution
0

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