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 11:13am
Edited 10-Aug-12 11:24am
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 Sergey Alexandrovich Kryukov 288
1 _Amy 270
2 Maciej Los 220
3 Manfred R. Bihy 200
4 CHill60 180
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,347
2 Maciej Los 3,799
3 Peter Leow 3,558
4 CHill60 2,702


Advertise | Privacy | Mobile
Web02 | 2.8.140721.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