mvc教學 - asp.net mvc vs asp.net core



為什麼ASP.NET會拋出這麼多異常? (3)

其他(可能有用)信息:

原因很多,這可能是因為網站/ webapp沒有favicon.ico文件。

如果實際的異常是:System.Web.StaticFileHandler.GetFileInfo它顯然是找不到的文件。 如果你沒有在瀏覽器上看到實際的404錯誤,那可能是因為瀏覽器在找不到favicon.ico時會悄悄地開展業務。

巧合的是,我看了一下Visual Studio的調試輸出。 我可以看到拋出數以百計的各種異常。 我檢查了另一個基於ASP.NET的解決方案,它顯示了相同的行為。 為什麼拋出所有這些例外? 我不敢相信這對整體表現有好處,是嗎? 請看下面的摘錄。 它是appr的輸出。 30秒衝浪。 大多數是HttpExceptions,但也有FormatExceptions和ArgumentOutOfRangeExceptions。 這些都不會影響使用。 什麼都沒有崩潰。 有沒有人有解釋,因為它似乎是“正常的”?

A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
'w3wp.exe' (Managed): Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a402e511\e6aaa0de\App_Web_vdj_eurz.dll', Symbols loaded.
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll

Answer #1

我不確定是什麼導致它,但我知道你怎麼能找到(更好,對吧?:))。

在Visual Studio中:

  • 單擊“調試”菜單
  • 點擊“例外......”
  • 檢查“公共語言運行時異常”中的“Thrown”

這將使Visual Studio在任何異常上暫停調試器,以便您可以檢查實際發生的情況。 (不影響生產代碼,僅在VS中停止)

作為旁注,您可能希望實現諸如自動例外電子郵件或類似的東西,以從生產站點獲取更多信息。

請注意,您可能無法捕獲VS中的所有異常(第一次異常有時可能有點難以捉摸)。 如果你想要更加強硬,你可以讓Visual Studio調試器調試.Net Framework 。 你的目標應該是看到完整的異常+堆棧跟踪,這在大多數情況下會告訴你所有的錯誤。

一個好的做法是擺脫異常(找到原因和修復),不要隱藏或忽略它們。

編輯

同樣值得一提的是,“ 第一次機會異常 ”是一種可能被try-catch捕獲的異常。 .Net中的某些內部函數會在滿足某個條件時拋出異常,這是Visual Studio /調試工作方式的一部分,並不意味著某些事情已經崩潰。 Visual Studio將為您記錄這些內容,以防您需要它們,但這並不意味著您必須對它們採取行動。






iis