Click here to Skip to main content
12,401,984 members (32,198 online)
Rate this:
 
Please Sign up or sign in to vote.
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
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
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2016
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