Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server , +
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 10-Aug-12 12:13pm
Edited 10-Aug-12 12:24pm
v2
Comments
Christian Amado at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

In Web.config
<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?)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

if(Session["userid"].toString==null)
{
//Redirect to login page
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100