Question

  Asked: Feb 12 2008   6:40 AM GMT
  Asked by: Blue


asp.net/c# session timeout


C, ASP.NET

hi ,
I am currently doing a login page. I would like to prompt the user by create a pop out text when the session is ending soon. After that the page will be redirected to the login page. can anyone help me with that. the following is my program.

protected void Page_Load(object sender, EventArgs e)
{
// if (IsPostBack)
// {

if (Page.IsPostBack)
{

Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) + "; URL=Login.aspx");

}


}
}

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



Most people don't do this as the value is far outweighed by the difficulty developing it due to the request/response
nature of web servers. How many sites can you think of that do this?

Also, how many users do you know will want to have to do something on your site, just to keep the session alive?
If it's that important, just raise the timeout level (scalability/performance issues) or have something in the background
reposting (e.g. ajax update panel or similar).

And what if every site started doing this? Popup hell for users if their browsing style matches mine

The typical way of managing this, is to give the user a "keep me signed in" option, implement that in your login
page so they don't care about the session timeouts because the sign in is transparent.


Having said that, how do you want it to happen?

Do you want this to happen on postback? If so, there is no point because on postback the session will eiher be
refreshed or will have already timed out.

If you want this to be initiated by the server, i.e. server detects upcoming session timeout and sends message to client,
which then displays the popup, then you have to conquer the problem of the server detecting the event in advance,
and the fact that the server doesn't have a communication pathway open to the client (unless you get fancy with
java or something). Too hard.

So doing it on the server is pointless.

The best way to do this would be to put in a little javascript on every page (perhaps in a master page) that issues a
time based function call in x minutes (where x is your timeout less say 1 minute). The javascript function displays
the popup. This is the closest you can approximate and is still flawed (e.g. when user goes back and forth in
browser history, )

I'd forget about it and just stick with the "whoops, you timed out" or "keep me signed in" pattern.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development.

Looking for relevant Development Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register