Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
plz help me with Session..

i have gone through all the code on internet.. and even try every thing nothing working..
plz help me step by step creating and executing..



i appreciate the help.. i have also gone through all these link below ...
i want it automatically to redirect to login page.. not by clicking the button when the session ends..

if any one know what exactly the code should be written in "Session_end --> Global.aspx" guess this will solve my problem and redirect to login page automatically when session time is out..
Posted
Updated 1-Oct-12 23:09pm
v2
Comments
Sandeep Mewara 30-Sep-12 14:01pm    
Do you have FormsAuthentication implemented in your application? You will have different answer based on it.

void Session_Start(object sender, EventArgs e)
{
Response.Redirect("LoginPage.aspx");
}

Under Global.asax file
 
Share this answer
 
v2
One more...way of doing it

protected void Page_Init(object sender, EventArgs e)

{

if (Context.Session != null)

{

if (Session.IsNewSession)


HttpCookie objCookie= Request.Cookies["ASP.NET_SessionId"];

if (objCookie!= null)

{

string objCookie= objCookie.Value;

if (objCookie!= string.Empty)

{

// Here we go...it's a time out or new session.......

Response.Redirect("Login.aspx");

}

}

}

}

}
 
Share this answer
 
C#
protected void Page_Load(object sender, EventArgs e)
   {
           if(Session["UserName"]==null)
           {
               Response.Redirect("Login.aspx");
           }
   }
 
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