在Global.asaxASP.NET C#的Application_Error没办法访问会话变量
问题说明
我有我的错误处理的设置来跟踪所有的异常,写我们需要一个数据库中的信息,并通过电子邮件发送出去谁需要了解有关该错误,以解决它的开发者。当页面完全加载之前发生的错误,我遇到的问题是。在这种情况下,会话变量我想跟踪不在的Application_Error可用。所以,我这样做,这样我就不是我的错误处理得到一个错误,但必须有一个更好的办法。此外,如果在提交表单的出现页面加载和错误,则会话变量是可用的。
I have my error handling setup to track all exceptions and write the information we need to a database and email out the developers who need to know about the error in order to fix it. The problem I run into is when the error occurs before the page has fully loaded. In this case the session variables I want to track are not available in Application_Error. So I do the following so that I don't get an error in my error handling, but there has to be a better way. Also if the page loads and the error occurs on submission of the form then the session variables are available.
try
{
user_name = System.Web.HttpContext.Current.Session["User_Name"].ToString();
user_number = System.Convert.ToInt32(System.Web.HttpContext.Current.Session["User_Number"].ToString());
}
catch (Exception ex)
{
user_number = 0;
user_name = "N/A";
}
任何帮助是极大的赞赏。
谢谢!
Any help is greatly appreciated. Thanks!
正确答案
有没有错,你在做什么,但一个
There's nothing wrong with what you're doing, although an
if ( null != System.Web.HttpContext.Current.Session )
会比你的try-catch块多外科手术。
would be more "surgical" than your try-catch block.
会议未初始化,直到AcquireRequestState事件添加,因此任何这点之前发生的错误将不会有会话变量。
Session is not initialized until the AcquireRequestState event, so any error occurring before this point will not have session variables available.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfieae
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20