Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Dear all,

How to redirect user to login page if the session time out in asp.net C#.

suppose if the user is idle. then the page must be redirect to login page.

Please help Thanks in advance.
Posted
Updated 10-Aug-12 11:24am
v2
Comments
Christian Amado 10-Aug-12 17:24pm    
As I know asp.net does it automatically if you have LoginUrl set in your forms section in the web.config

In Web.config
XML
<authentication mode="Forms">
      <forms loginUrl="login.aspx" defaultUrl="homePage.aspx" timeout="yourTime" name="UserLogin" path="/"/>
    </authentication>

In login.aspx.cs
FormsAuthentication.RedirectFromLoginPage(username, persistent cookie?)
 
Share this answer
 
C#
if(Session["userid"].toString==null)
{
//Redirect to login page
}
 
Share this answer
 
Hi,

You can implement Form authentication which is cookie based and cookie will expire after the timeout set in config file and user will be redirected to the given page.

Refer below links for implementing form based authentication.

http://support.microsoft.com/kb/301240[^]
Understanding and Implementing ASP.NET Custom Forms Authentication[^]
Role-based Security with Forms Authentication[^]

Or set user session after login and check user session in each page or create a base class in each page in which you can check user session.

Hope this will help you.
 
Share this answer
 

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