简体   繁体   English

从global.asax中的Session_end重定向到另一个页面

[英]Redirecting to another page from Session_end in global.asax

I need to redirect the user to the login page on session timeout. 我需要在会话超时时将用户重定向到登录页面。 The issues with Session_End method in the global.asax are: global.asax中的Session_End方法存在以下问题:

  1. It does not support Response.Redirect or Server.Transfer 它不支持Response.Redirect或Server.Transfer
  2. Any attempt to use HttpContext.Current.Response results in 'Object Reference not set to an instance of an object' error 任何使用HttpContext.Current.Response的尝试都会导致“对象引用未设置为对象的实例”错误
The second error is understandable since on session time out, the current session would be terminated and set to null. 第二个错误是可以理解的,因为在会话超时时,当前会话将被终止并设置为null。
What I want to know is whether is it possible to redirect the user directly (and specifically) from session_end to another page. 我想知道的是,是否有可能将用户直接(特别是)从session_end重定向到另一个页面。 There are methods which work (not using the session_end method), but all of them require a request to the server(such as a refresh,which I don't want). 有一些有效的方法(不使用session_end方法),但是所有方法都需要向服务器发出请求(例如刷新,我不希望这样)。 Can i do this without using javascript?(more important, should I?) 我可以不使用JavaScript来做到这一点吗?(更重要的是,我应该吗?)
Thanks in advance! 提前致谢!

Isn't Session_End raised directly on server, without any interaction from user? 没有用户的任何交互,不是直接在服务器上引发Session_End吗?

What happens, when I go to your page (and start a session), close browser window and never return? 当我转到您的页面(并开始一个会话),关闭浏览器窗口并且永不返回时,会发生什么情况? Then it's understandable, that HttpContext.Current.Response is null. 可以理解HttpContext.Current.Response为null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基类如何从Global.asax调用Session_End方法? - How does the baseclass call the Session_End method from Global.asax? 在Session_end事件上重定向到另一个页面 - Redirecting to another page on Session_end event 会话变量值并非始终在Global.asax Session_end中可用 - Session variable value not always available in Global.asax Session_end 在数据库中注销日志并在Global.asax中的Session_End()后面删除cookie - With LogOff record in database and deleting cookie behind the Session_End ( ) in Global.asax ASP.NET MVC4 - Session_End - 如何在Global.asax的Session_End中获取当前登录用户的名称? - ASP.NET MVC4 - Session_End - How can I get the currently logged on user's name in Session_End of Global.asax? Global.asax.cs中的Session_Start和Session_End - Session_Start & Session_End in Global.asax.cs 如何处理 global.asax 中的 session 结尾? - How to handle session end in global.asax? 响应重定向使session_end在全局asax中 - response redirect makes session_end in global asax Global.asax.cs中的Session_End不触发 - Session_End in Global.asax.cs not firing ASP.net MVC 5 - 如何从 Global.asax.cs 中的 session_end() 事件重定向到操作方法 - ASP.net MVC 5 - How to redirect to action method from from session_end() event in Global.asax.cs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM