2017-04-25 37 views
0

我在Web窗体中有一个ASP.NET C#。当会话超时时,我重定向到登录页面。这里是我的母版页代码:ASP.NET C# - 如何显示会话已过期的消息?

Response.AppendHeader("Refresh", Convert.ToString(Session.Timeout * 60) + "; URL="); 
if (HttpContext.Current.Session["authenticated"] == null) 
{ 
    Response.Redirect("~/"); 
} 

我怎样才能让一个通知消息出现在登录页面,当它被重定向因为会话超时的呢?例如,该消息将是“您的会话已过期”。

+1

你知道如何通过查询字符串传递信息? – mason

+0

查看@mason的评论。做一个搜索。这和答案一样好。 – Rahul

回答

0

谢谢你,我改变了代码:

Response.AppendHeader("Refresh", Convert.ToString(Session.Timeout * 60) + "; URL=?error=sessionexpired"); 
if (HttpContext.Current.Session["authenticated"] == null) 
{ 
    Response.Redirect("~/?error=invalidsession"); 
} 

然后,在我的登录页:

if (Request["error"] == "sessionexpired") { 
    msg = "Your session has expired"; 
} 
else if (Request["error"] == "invalidsession") 
{ 
    msg = "Please sign in to continue"; 
}