.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Set session Timeout and Auto Redirect

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net


I am creating web application. In that I want to set session timeout (not idle timeout). If a user logged in that time the session time will start and it automatically should detect session timeout the page should redirect to another page. How can I acheive this.

View Complete Post

More Related Resource Links

session timeout redirect in ajax calls


If a normal session timeout occurs we could handle the session timeout.

But say we are using a lot of ajax calls, webhandlers etc. How would we catch session timeout here and redirect to error/login page.


Auto logout and redirect to login page when session expires using asp.net

In this article I will explain you how to auto logout and redirect to login page when users session expires within specific period.

How to set session timeout and clear session in asp.net C# ? And kill session when close the web app


hi ,

How to set session timeout and clear session in web.config and login.aspx  ? And when we close the web application , the session must be cleared ?

I have use session.abandon as per below but is not working . Pls advise .


        protected void btnLogout_Click(object sender, EventArgs e)



session timeout


hi there,

is it possible that session time out is calculated in seconds and not in minutes?

i am setting it at web.config, global.asax, default.aspx and at the web server to 30 (minutes) and session last exactly for 30 seconds.



Session Timeout increase to 2 hours.



    for Business needs i am planning to increase the session timeout to 2 hours(120 min) in one application, i am using sql server session state. if i increase to 2 hours of session time out, how it will effect the performance of application and web server.

   Could any one help me on this.






Warning users before Session Timeout

Hi, In my web application, I want to alert users 5 minutes before their session timeout. If the users want, they can either extend their session or ignore the message - in which case after session timeout they will be redirected to the login page (I'm also using forms authentication in my site, so have set the authentication cookie expire time to the session timeout). I know I can do the alert with window.setTimeout, but I want to get user's respond and refresh the page if they want a session extension. How can I do that, in which event and whether I can do this in C# code behind. And also, should I implement this in the base page or somewhere else? How can I implement the auto page refresh - should I use a hidden button and click it from Javascript? It's great if someone can give a sample code for this.  

how to redirect user to login page if session is null

i have 2 page,1.login.aspx ---  2.welcome.aspxin my login.aspx im storing username into sesssion as below:Session["usernm"] = txtUsername.Text;in my welcome.aspx  pagein page_load event if (Session["usernm"]==null)        {            Response.Redirect("Login.aspx");        }----- here if i manulally paste the url ( http://localhost:4125/Loginado/welcome.aspx) it should go to  login.aspx for user credentialsbut its going directly to welcome.aspx  page.

Ajax Session timeout problem

Hi,  I have some problems when using AJAX with updatepanels. I have an ASP.NET webapplication with a login that uses form authentication with the timeout set to 5 min. After 5 min of idle the site should be redirected to the login.aspx page. My problem is that after using the site for 5 minutes when clicking on contents inside an updatepanel I get a messagebox with the following error: A Runtime Error has occurred.Do you wish to Debug? Line: 4723Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 12031  I think that it has something to do with the ajax updatepanel since when I remove the updatpanels this problem does not appear. Instead the site is redirected to login.aspx as expected. When searching on the problem on google I see alot of people having similar problem, but I haven't found suitable solution. Any suggestions?

Asp.net Pages Getting session timeout

in my website there is a folder which requires authunteication/jobseekers/but after sometimes, the session("cid") is "", that means there is no value of candidate in the session("cid") field, but iam able to browse the jobseeker folderiam not using asp.net default authenticaiton method, iam manualy authenticating themnow my concern iswhen there is no value in session("cid") the user must be prompted to login againhow can that be doneif put a check in master page for session("cid")but i also have login.aspx in that jobseekers folderso do i need to have login.aspx page outside the jobseeker folder and shall i write session("cid") in master page

modal popup extender..session timeout

hi, i actually want to give a popup 2 min before the session timeout, i have actually found out a way to do that but i want to use modal pop up extender instead of javascript....... how should i use this,how do i create the pop up window first and then how do i call it from page load of each page, what should be the targetcontrolid,please help me out.   thank you

How to catch error in session variable in globals.asax(Application_Error) and redirect to same page

Hi, i have a login page where username got to enter his/her username or password. When you try to enter any scripting over there eg:'<asd>' it gives an error  'Server Error in '/' Application' 'A Potentially dangerous Request. Form value was detected from client' I don't want to redirect user to custom error page when such unpredictable error occurs. infact i got a label on the same page itself where error's are displayed. how can i display such errors on this very same label. can i do that using globals Application_Error ?. Session variable not working here. Please give me the exact steps for how i can catch and display the error which are not validated. waiting for reply thanks and regards, Learning Programmer

Asp.net Ajax and session timeout

Hi, How do I handle a session timeout when using a updatepanel ?When the user session has timed-out and I click a button I get this error Sys.WebForms.PageRequestManagerParserErrorException - The message received from the server could not be parsed.I have tried to set EnabledEventValidation to false on the page but that didnt work, I have also tried to override the preInit on the page...didnt work either.Any ideas ?

IIS 5.1 PHP Killed my session Timeout!

 I followed the instructions to install php on IIS5.1 at php.net and ever since my asp.net sessions keepalive seems to die after 60 seconds of inactivity? Please help.

Losing Session after redirect.


Hello everyone.


I am having an issue with a piece of code. Everything else on the site works perfect except for this part.
Basically, there is a button on a page that says 'Download images', what this does is compress a list of files and then redirects the user to the .zip file.

EDIT: The problem I am having is as soon as the 'Download Images' button is clicked and they are prompted to download the file their session is lost. It does not matter if they download the file or not, as soon as the button is hit the file copy process takes at most 10 seconds and then the download box is shown.

Here is the code on the 'Download Images' button:


Dim bpoClass As New BpoClass


Response.Redirect("zipfiles/" & Request.QueryString("UniqueID") & ".zip")


Now, if I comment out the bpoclass.compresszipfile function, it works; the session is not lost. So it  might have something to do with the code inside the fu

Check session timeout and warn user before timeout


I know there are several articles explaining how to warn the user before their session times out, but so far none of them have worked for our scenario, so I'm hoping someone here will be able to help me figure this one out...  Here's what we've got:

Our application uses SQLServer to store session state.  We've got it set to timeout in 60 minutes.  Unfortunately (I fought hard against this, but lost the battle) our application uses popups for several major screens.  So tracking the session timeout on the client side doesn't really work, because I have no idea what window the user is in at any given point.  I've tried the solution where you inject Javascript into the page using the current session timeout on each request, but again, because the user could be actively using the application in a different window, it doesn't work for us.  So I guess I have a couple key questions:

  1. Is there any way to get the timeout for a session without triggering a request to the server, which would just renew the session?
  2. Is there a way to track the session timeout value across multiple windows? 
    I believe there is a limit to the number of "branches" the main window can have in our app.  In other words, the user can only be 2 levels deep from the main/root window, s

Alert on session timeout


Im implementing a minor function that SHOULD be no problem at all. However, I cant get it to work.

Currently, when a users session times out, they get redirected to our login screen. However, I want to add an alert box that tells the user why they were logged out. I want to place the code for this in the code behind, in the same function that checks the session. Currently, the code looks like this:

Protected Overrides Sub OnLoad(ByVal e As EventArgs)
        If SessionManager.User Is Nothing Then
            Response.Write("<script>alert('Session expired.');</script>")
            Exit Sub
        End If

The alert code for the alert works, but when I let my session time out, no alert shows, I just get redirected.

Im considering just redirecting to an error page, but I want to cut down the loading time as much as possible, thus I'd prefer to fire the alert as it redirects to login.

Session time out alert box and redirect login page


Dear all,

Now I am using Form authentication for my website. 

It is something like that below. But if I left the website without using it for quite some time and when I used it back, it is redirected to the login page. 

The one I want to know is that it is because of session expire or cookies expire. And if it is session expired, I want to show the alert box and redirect to the login page. And one more thing is that if the user keeps on using the website, I want to extend the session expire time. If you do not mind, I want to have some references for this scenario. Thank you so much.


If myUser.IsValidUser(txtUserName.Text.Trim, txtPassword.Text.Trim) = True Then
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend