ASP.NET C# Application_Error in Global.asax cannot access Session variables

二次信任 提交于 2019-12-04 09:56:25

There's nothing wrong with what you're doing, although an

if ( null != System.Web.HttpContext.Current.Session )

would be more "surgical" than your try-catch block.

Session is not initialized until the AcquireRequestState event, so any error occurring before this point will not have session variables available.

This is what you'll need to do. The user can go to any page through a bookmark or by knowing the URL. Therefore, the page could possibly be retrieved by the user before any values are set. So that is what you'll need to do to make sure the code doesn't break.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!