簡體   English   中英

應用程序錯誤

[英]Application_Error

我最近發現生產中的IIS工作進程每周崩潰2-3次。 我在異常日志中注意到它是因為UnhandledException。 我調查過,發現Global.asax沒有Server.Transfer調用。

然后我做了一些谷歌搜索,似乎最好使用Response.Redirect。 這是真的,我繼續對此發表評論......

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
        if (null != Context && null != Context.AllErrors)
            System.Diagnostics.Debug.WriteLine(Context.AllErrors.Length);

        //bool isUnexpectedException = true;
        HttpContext context = ((HttpApplication)sender).Context;

        Exception ex = context.Server.GetLastError();
        if (ex.InnerException != null)
            ex = ex.InnerException;

        LogManager.ExceptionHandler(ex);

        Server.Transfer("GeneralError.aspx");
    }

這取決於您是否希望您的用戶看到“重定向”。 我個人會在這種情況下使用Response.Redirect。

看看這兩個差異的答案: https//stackoverflow.com/a/224577/1260077

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM