2011-09-19 25 views
2

我有一個使用System.Web.Routing的ASP.NET C#web應用程序。使用System.Web.Routing的Web應用程序

由於某些原因,我無法捕捉到所有HTTP錯誤。例如:

  • www.domain.com/adfasdf/asfadf/ - 正確地重定向到自定義頁面
  • www.domain.com/fafad/afdad/asfaf/ - 返回默認的錯誤頁面,看起來像:

404 page sample

的web.config:

<customErrors mode="On" defaultRedirect="Error"> 
    <error statusCode="404" redirect="Page-Not-Found"/>  
</customErrors> 

我不能捕獲Global.asax文件中的錯誤。

是否有無論如何將用戶重定向到錯誤頁面的根站點下的任何錯誤(處理和未處理)?

回答

0

你可以試試這個:

<system.webserver> 
... 
<httpErrors existingResponse="PassThrough" /> 
... 
</system.webserver> 
0

在你的web.config,

添加下面的章節來處理錯誤

<system.webServer> 
... 
    <httpErrors errorMode="Custom"> 
     <remove statusCode="404" subStatusCode="-1"/> 
     <remove statusCode="500" subStatusCode="-1" /> 
     <error statusCode="404" prefixLanguageFilePath="" path="/Error404.aspx" responseMode="Redirect"/> 
     <error statusCode="500" prefixLanguageFilePath="" path="/Error500.aspx" responseMode="Redirect" /> 
    </httpErrors> 
... 
</system.webServer> 

<system.web> 
... 
<customErrors defaultRedirect="/Error" mode="RemoteOnly"> 
    <error statusCode="500" redirect="/Error500.aspx" /> 
    <error statusCode="404" redirect="/Error404.aspx"/> 
</customErrors> 
... 
</system.web>