2013-02-08 70 views
0

我想處理Global.asax的Application_Error事件中的未捕獲異常。目前,它看起來像Global.asax Application_Error問題

Sub Application_Error(ByVal sender as object, ByVal e as EventArgs) 
    Server.ClearError() 
    Response.Redirect("~/ErrorPages/GenericError.aspx") 
End Sub 

拋出一個全新的例外在另一頁的Page_Load中與

Throw New Exception() 

什麼最終實際發生的情況是,執行從來沒有離開源頁面,並拋出默認ASP錯誤引用我的例外。爲什麼它不被髮送到我的錯誤頁面?

編輯:固定Response.Redirect。現在的樣子:

Response.Redirect("http://mysite/ErrorPages/GenericError.aspx") 

還提出,由krshekhar建議建議改變我的web.config文件。雖然我現在被髮送到我的錯誤頁面,但它使用的是默認重定向,而不是我在Application_Error中提供的重定向。任何其他想法?

+1

有你在web.config中打開或關閉了CustomerErrors? – tomasmcguinness 2013-02-08 16:38:46

+1

使用像'Response.Redirect'這樣的FYI會拋出一個'ThreadAbortException'。 [MSDN entry](http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.100%29.aspx) – MikeSmithDev 2013-02-08 17:01:06

回答

1

的解決方案應該是customErrors mode="On"
唯一的問題查找您qustion是customError web.config中的條目應該是如下

<configuration> 
    <system.web> 
     <customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> 
      <error statusCode="403" redirect="NoAccess.htm" /> 
      <error statusCode="404" redirect="FileNotFound.htm" /> 
      ... 
     </customErrors> 
    </system.web> 
    </configuration> 

幫助鏈接
ASP.NET custom error page - Server.GetLastError() is null
CustomErrors mode="Off"

+0

按照建議更改了'web.config'。我現在進入錯誤頁面,但它使用來自''的默認重定向,而不是我在'Application_Error'中給出的重定向。 – Crimius 2013-02-08 19:54:53

+0

@Crimius刪除'defaultRedirect'並使用'Response.Redirect(「pagename」,false)' – 2013-02-09 04:01:40

+0

由於''標記中沒有默認重定向,頁面現在出錯。 – Crimius 2013-02-11 13:34:57

相關問題