【发布时间】:2017-11-22 20:53:59
【问题描述】:
我的代码中有两个会话:
用于用户登录验证的会话["Email"]
Session["prevUrl"] 记住上次访问的页面
我想知道如何在我的 webconfig 文件中管理会话超时。我只希望 Session["Email"] 超时,以便用户可以重定向到他们重新登录时访问的最后一个页面。目前两个会话都在 1 分钟后超时
谢谢
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# 页面加载
protected void Page_Load(object sender, EventArgs e)
{
Session["prevUrl"] = Request.Url;
if (Session["Email"] == null)
{
Response.Redirect("Login.aspx");
}
}
【问题讨论】: