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
C#
sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="1">
sessionState>Global.asax.cs
C#
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
C#
protected void Page_Load(object sender, EventArgs e)
{
Session["prevUrl"] = Request.Url;
if (Session["Email"] == null)
{
Response.Redirect("Login.aspx");
}
}
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jun 20, 2017, 4:50 AM EDT
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.
Eric Mbiada72 reputationPosted Jun 20, 2017, 5:37 AM EDT
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");
}
}
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 20, 2017, 5:41 AM EDT
"InProc" cookieless="true"timeout="60"/>Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 20, 2017, 8:09 AM EDT
Vivek KumarRank #272 · 9.3K reputationPosted Jun 20, 2017, 10:28 AM EDT