简体   繁体   中英

Custom error redirection through web.config does not work

I`m trying to implement redirect to custom error pages, when error happens.

I tried next way:

<customErrors mode="On" redirectMode="ResponseRewrite">
  <error statusCode="403" redirect="/Errors/AccessDenied" />
  <error statusCode="404" redirect="/Errors/PageNotFound" />
</customErrors>

And also method with <httperrors> inside web.server tag.

None of the methods works. Instead of redirecting to error pages, i see default error:

愚蠢的错误

What you can advice to solve that problem? I`ll be very gratefull to any help

It looks like the screen is throwing a http 404 error. Assuming you have no other overriden methods for catching these errors in your application, try adding the following to the web.config

<system.webServer>
   <httpErrors errorMode="Custom" existingResponse="Replace">
     <remove statusCode="404" />
     <error statusCode="404" path="/Errors/whatever" responseMode="ExecuteURL" />
   </httpErrors>
</system.webServer>

Did you try remove status code 404?

<system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/Errors/PageNotFound" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM