Application_Error:如何保存异常信息?

发布于 2024-10-09 07:47:15 字数 536 浏览 0 评论 0原文

我使用以下代码来捕获应用程序中的异常,并将它们保存在 Session 对象中。然后,从应用程序自动重定向到的错误处理程序页面中的 Session 检索异常:

    protected virtual void Application_Error(Object sender, EventArgs e)
    {
        try
        {
            Exception ex = Server.GetLastError();
            Session["exception"] = ex;
        }
        catch { }
    }

此代码有一个问题:

如果格式错误的路径进入,则 Session 不可用:"example .com/"foo" - 访问它时抛出异常,并在错误页面中从 Session 对象中检索到 NULL

在应用程序中保存异常信息并将其传递给错误的更好方法是什么处理程序操作?

I am using the following code to capture exceptions in the application, and save them in the Session object. The exception is then retrieved from Session in the error handler page to which the app automatically redirects:

    protected virtual void Application_Error(Object sender, EventArgs e)
    {
        try
        {
            Exception ex = Server.GetLastError();
            Session["exception"] = ex;
        }
        catch { }
    }

I have one problem with this code:

Session is not available if a malformed path gets in: "example.com/"foo" - Exception is thrown when accessing it, and NULL is retrieved from Session object in the error page

What is a better way to save exception information in the application and pass it to the error handler action?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏见 2024-10-16 07:47:15

如果您尝试记录异常,请查看 elmah 项目。

Scott Hanselman 有很好的介绍

If you are trying to log exceptions then take a look at the elmah project.

Scott Hanselman has a good introduction

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文