ASP.NET MVC 重定向 OnEnd
ASP.NET MVC redirect OnEnd
我在 Global.asax
中的 Session_OnEnd() 方法中尝试重定向
如果我输入
public void Session_OnStart()
{
HttpContext.Current.Response.Redirect("http://www.google.es");
}
然后转到 Google 但是当我尝试这个时 onEnd...
public void Session_OnEnd()
{
HttpContext.Current.Response.Redirect("http://www.google.es");
}
显示
"NullReferenceException was unhandled by user code", Object reference
not set to an instance of an object.
有人帮我解决这个问题吗??
您对 Session_OnEnd() 的发生方式有误解。当会话超时时会发生这种情况,这通常意味着用户在一段时间内没有活动连接。由于没有活动连接,因此没有活动请求,因此您无法重定向任何人。
我认为您想要做的是在会话超时时重定向用户浏览器,而服务器无法做到这一点。您必须在 JavaScript 的客户端上,在闲置超时后执行此操作。
我在 Global.asax
中的 Session_OnEnd() 方法中尝试重定向如果我输入
public void Session_OnStart()
{
HttpContext.Current.Response.Redirect("http://www.google.es");
}
然后转到 Google 但是当我尝试这个时 onEnd...
public void Session_OnEnd()
{
HttpContext.Current.Response.Redirect("http://www.google.es");
}
显示
"NullReferenceException was unhandled by user code", Object reference not set to an instance of an object.
有人帮我解决这个问题吗??
您对 Session_OnEnd() 的发生方式有误解。当会话超时时会发生这种情况,这通常意味着用户在一段时间内没有活动连接。由于没有活动连接,因此没有活动请求,因此您无法重定向任何人。
我认为您想要做的是在会话超时时重定向用户浏览器,而服务器无法做到这一点。您必须在 JavaScript 的客户端上,在闲置超时后执行此操作。