Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
detetcting a session timeout and redirct page automatically to login page in asp.net..
if user on any page...

how to do it...

i have search everything


thanks in advance
Posted

First you need to handle Session_Start & Session_End in Global.asax. Have a variable in Session like below. Sorry the code was in VB, you can easily convert this into C#.

VB
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when a new session is started
    Session("UserLogged") = False
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when a session ends.
    ' Note: The Session_End event is raised only when the sessionstate mode
    ' is set to InProc in the Web.config file. If session mode is set to StateServer
    ' or SQLServer, the event is not raised.
    Session("UserLogged") = False
End Sub


Then write your code to check Session("UserLogged") whenever an action is performed. Based on the value, redirect to Login page.
 
Share this answer
 
v2
Hi,

Implement form authentication and it will do all the thing.

The below link help you to implement form authentication.

http://support.microsoft.com/kb/301240[^]

http://www.codedigest.com/Articles/ASPNET/112_Implementing_Forms_Authentication_in_ASPNet_20.aspx[^]

But if your user are anonymous then you should go for coustom authentication or use Session_Start and Session_End event avail in global.asax page.
 
Share this answer
 
v2
Comments
wings_ 6-Oct-12 1:08am    
k

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900