• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在Global.asaxASP.NET C#的Application_Error没办法访问会话变量

用户头像
it1352
帮助1

问题说明

我有我的错误处理的设置来跟踪所有的异常,写我们需要一个数据库中的信息,并通过电子邮件发送出去谁需要了解有关该错误,以解决它的开发者。当页面完全加载之前发生的错误,我遇到的问题是。在这种情况下,会话变量我想跟踪不在的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!

正确答案

#1

有没有错,你在做什么,但一个

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
系列文章
更多 icon
同类精品
更多 icon
继续加载