Hello
I have two sessions in my code:
Session["Email"] for user Login Authentication
Session["prevUrl"] to remember last page visited
I want to know how to manage the session timeout . I only want the Session["Email"] to timeout so the user can be redirected to the last page visited when they log back in. At the moment both sessions are timing out after 1 min
Thanks
Web.config
<sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="1">
sessionState> Global.asax.cs
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
if (Session["prevUrl"] != null)
{
Response.Redirect((string)Session["prevUrl"]); //Will redirect to previous page visited
}
else
{ //Redirect to Login Page if Session is null & Expires
Response.Redirect("Login.aspx");
}
} C# Page Load
protected void Page_Load(object sender, EventArgs e)
{
Session["prevUrl"] = Request.Url;
if (Session["Email"] == null)
{
Response.Redirect("Login.aspx");
}
}
Vivek KumarPosted Jun 20, 2017, 2:28 PM
Rajeesh MenothPosted Jun 20, 2017, 12:09 PM
Rajkiran SwainPosted Jun 20, 2017, 9:41 AM
Eric MbiadaPosted Jun 20, 2017, 9:37 AM
Hi Manikandan
I set web.config as you see below. But the form does not timeout after 1 min as expected. But after 10 min the page is redirected to the login page
Do I need to change something somewhere else?
Thanks{
// Code that runs when a new session is started
if (Session["prevUrl"] != null)
{
Response.Redirect((string)Session["prevUrl"]); //Will redirect to previous page
}
else
{
//Redirect to Login Page if Session is null & Expires
Response.Redirect("Login.aspx");
}
}
Manikandan MurugesanPosted Jun 20, 2017, 8:50 AM
Refer this Link : http://www.c-sharpcorner.com/blogs/how-to-set-session-timeout-in-asp-net1
Forms authentication uses it own value for timeout (30 min. by default). A forms authentication timeout will send the user to the login page with the session still active. This may look like the behavior your app gives when session times out making it easy to confuse one with the other.