2009-11-06 41 views
0

我在共享主機上運行我的應用程序。在共享主機上調試ASP.Net web.config問題

當我在我的開發服務器上運行最新的更改時,一切正常 - 當我上傳時,我看到通用的「錯誤發生但未顯示」消息。

如果我改變我的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 protected]")) 
     Dim SMTP As New SmtpClient 
     SMTP.Send(Message) 

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

回答

1

this就是這樣。

+0

我會給它一個去,但我_believe_錯誤發生之前ASP.Net完全初始化,所以我不知道這是否會抓住它 - 我會盡快回復您 – Basic 2009-11-06 20:36:03

+0

哇,我不能更加錯誤。它的作用就像一個魅力 - 我已經通過電子郵件向我發送了錯誤細節。我會用一些代碼發佈一個額外的答案,以防將來幫助某人。 – Basic 2009-11-06 22:18:37

+0

我的道歉和感謝糾正 - 似乎我需要其他人投票刪除答案? – Basic 2009-11-07 19:10:17