【问题标题】:Display Exceptions in ASP.NET / Azure在 ASP.NET / Azure 中显示异常
【发布时间】:2010-11-29 22:28:02
【问题描述】:

我想在 Azure ASP.NET Web 应用程序中显示一个自定义错误页面

   <p>Oops - something went wrong.</p>
<p>The most common problem is that you tried to do something that the database enforces shouldn't happen.</p>
<p>The error is:</p>

在 web.config 我有:

<customErrors mode="On" defaultRedirect="Error.aspx" />

和 global.asax:

protected void Application_Error(object sender, EventArgs e)
        {
            Exception objErr = Server.GetLastError().GetBaseException();
            string err = "Error Caught in Application_Error event\n" +
                    "Error in: " + Request.Url.ToString() +
                    "\nError Message:" + objErr.Message.ToString() +
                    "\nStack Trace:" + objErr.StackTrace.ToString();
            EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error);
        }

问题:如何在 Error.aspx 页面上显示完整的异常?

【问题讨论】:

    标签: asp.net azure


    【解决方案1】:

    如果您使用的是 ASP.NET 3.5 SP1,请尝试将 redirectMode="ResponseRewrite" 属性添加到 customErrors 元素。这应该保留存储在Server.GetLastError() 中的异常信息。然后可以在Error.aspx页面添加标签,显示异常详情,即lblError.Text = Server.GetLastError().ToString()

    这是一个类似的 SO 问题:ASP.NET custom error page - Server.GetLastError() is null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-25
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      相关资源
      最近更新 更多