【问题标题】:Debugging ASP.Net web.config issue on shared host在共享主机上调试 ASP.Net web.config 问题
【发布时间】:2009-11-08 03:09:26
【问题描述】:

我在共享主机上运行我的应用程序。

当我在开发服务器上运行最新更改时,一切正常 - 当我上传时,我看到一般的“发生错误但未显示”消息。

如果我将 web.config 更改为包含

CustomErrors mode="off"

然后我仍然看到相同的错误消息。

我猜我最近的一项更改导致解析 web.config 时出现问题。

有什么方法可以检索此错误的详细信息?我知道的唯一方法是事件日志和服务器日志——我都无法访问。

非常感谢您的任何帮助


这里的代码可以为其他人节省一些时间。将格式化异常详细信息并邮寄。如果 Global.asax 不存在,请添加它。然后更新 Application_Error 方法。

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when an unhandled error occurs
    Dim ex As Exception = Server.GetLastError().GetBaseException()
    Dim ErrMsg As New Text.StringBuilder

    While ex IsNot Nothing
        ErrMsg.AppendLine(String.Format("Message : {0}", ex.Message))
        ErrMsg.AppendLine(String.Format("Source : {0}", ex.Source))
        ErrMsg.AppendLine(String.Format("Target : {0}", ex.TargetSite.ToString))
        ErrMsg.AppendLine("Stack: ")
        ErrMsg.AppendLine(ex.StackTrace)

        If ex.InnerException IsNot Nothing Then
            ex = ex.InnerException
            ErrMsg.AppendLine(">> Inner Exception >>>>>>>>>>>>>>>>>>>>>")
        Else
            ex = Nothing
        End If

    End While

    Try
        Dim Message As New System.Net.Mail.MailMessage
        Message.Body = ErrMsg.ToString

        Message.Subject = "MPW Error"
        Message.To.Add(New MailAddress("EMAIL_ADDRESS_HERE@example.com"))
        Dim SMTP As New SmtpClient
        SMTP.Send(Message)

    Catch FatalEx As Exception
        'Write to file, die or re-throw
    End Try
End Sub

【问题讨论】:

    标签: asp.net web-config shared-hosting


    【解决方案1】:

    this 是方法。

    【讨论】:

    • 我会试一试,但我相信错误发生在 ASP.Net 完全初始化之前,所以不确定这是否会捕获它 - 我会得到很快就会回复你
    • 哇,我大错特错了。它就像一个魅力 - 我已经通过电子邮件将错误详细信息发送给我。我会用一些代码发布一个额外的答案,以防将来对某人有所帮助。
    • 抱歉并感谢您的更正 - 似乎我需要其他人投票才能删除答案?
    猜你喜欢
    • 2010-11-23
    • 2013-07-03
    • 2018-02-19
    • 1970-01-01
    • 2021-06-14
    • 2012-04-02
    • 2011-03-27
    • 2019-06-27
    • 2016-05-21
    相关资源
    最近更新 更多