Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep session alive forever as stackoverflow

I need to keep the session live unless until the user clicks logout in my asp.net mvc(C#) application.

When the user closes the browser and opens again, the session should continue with the values.

I am trying to implement as in stackoverflow.

Any ideas/suggestions?

like image 917
Prasad Avatar asked Nov 19 '09 15:11

Prasad


People also ask

How do I keep my session alive forever?

If you need to keep sessions alive indefinitely without setting the timeout forever (therefor triggering murder by the server admin in some cases), a neat trick is to setup an Ajax "heartbeat" to ping back to the server while the browser is open and effectively do a "keep this session alive" trick.

How do I keep a session alive without reloading?

You can use javascript XHR, or as others call it, AJAX. Using ajax you can call a php script that refreshes your session every 10 minutes. :) This is as far as i can go to "exact".

How check session expired in asp net?

In asp.net, It is very simple to detect session time out and redirect the user to login page or home page. All you have to do is, specify the redirection page in session_start event handler in Global. asax file as shown below. If the session has timed out, the user will be redirected to the login page.


2 Answers

You say you want to keep the session alive "as in StackOverflow."... StackOverflow, like most secure sites, does not keep sessions alive indefinitely. It uses cookies to "remember" the login.

like image 200
Dave Swersky Avatar answered Oct 21 '22 19:10

Dave Swersky


if you use FormsAuthentication, you can do something like:

FormsAuthentication.SetAuthCookie("userName", true); 

That will create a cookie that is persisted across different browser sessions, and will achieve what you're looking for.

like image 23
oz. Avatar answered Oct 21 '22 20:10

oz.