开发者

Web Application with using System.Web.Routing

开发者 https://www.devze.com 2023-04-06 01:30 出处:网络
I have a ASP.NET C# web application that uses System.Web.Routing. For some reason I cannot catch all HTTP errors. For example:

I have a ASP.NET C# web application that uses System.Web.Routing.

For some reason I cannot catch all HTTP errors. For example:

  • www.domain.com/adfasdf/asfadf/ - correctly redirects to c开发者_开发百科ustom page
  • www.domain.com/fafad/afdad/asfaf/ - returns the default error page that looks like:

Web Application with using System.Web.Routing

web.config:

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

I am not able to catch those errors in the Global.asax file.

Is there anyway to redirect user to the error page for any error (handled and unhandled) under root site?


You can try this:

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


In your Web.Config,

Add following sections to handle errors

<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>

and

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号