我发现了一些类似的问题,但没有一个给我真正需要的。
这是事情,我已将其添加到我的 web.config
处理用户 session 过期:
<sessionState mode="InProc" timeout="1" />
1 分钟后,
Session_End
事件来自 Global.asax
提出:Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("Login.aspx")
End Sub
这不起作用,因为:
Response is not available in this context.
(顺便说一句,this question 得到了一个回答,告诉我们这是可以的,并且得到了赞成)。
我不想要任何花哨的东西。我只想要一种简单的方法,可以在 session 时间到期时将用户重定向到登录页面。就这样。
谢谢你。
最佳答案
描述
您可以使用 Page_Init
事件在 global.asax
样本
Protected Sub Page_Init(sender As Object, e As EventArgs)
If Context.Session IsNot Nothing Then
If Session.IsNewSession Then
Dim newSessionIdCookie As HttpCookie = Request.Cookies("ASP.NET_SessionId")
If newSessionIdCookie IsNot Nothing Then
Dim newSessionIdCookieValue As String = newSessionIdCookie.Value
If newSessionIdCookieValue <> String.Empty Then
' This means Session was timed Out and New Session was started
Response.Redirect("Login.aspx")
End If
End If
End If
End If
End Sub
更多信息
关于asp.net - session 超时后重定向到登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502295/