Search code examples
azure-web-app-serviceweb-confighttp-errorazure-appservice

Redirecting to custom error pages in Azure Application service doesn't work


I'm trying to redirect in case of an http error to a error page hosted in an external url making use of the element <httpErrors> in my web.config file in server. Currently I have the following configuration

<configuration>
  <system.webServer>
    <httpErrors errorMode="Custom" defaultResponseMode="Redirect">
      <error statusCode="404" path="https://my-custom-error-page.com" />
    </httpErrors>
  ...

and whatever I set as defaultResponseMode I cannot get the error page, and instead I'm still retrieving always the IIS error page.

someone knows what's missing?



Solution

  • Redirecting to custom error pages in Azure Application service doesn't work

    • Make sure your web.config is deployed in the wwwroot directory
    • Iam able to redirect to CustomError page with the below setting in web.config when an error occurs
    <httpErrors existingResponse="PassThrough" />
       <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" path="/public/404.html" responseMode="ExecuteURL" />
        </httpErrors>
    
    • Under <system.webServer> , Make sure you add
    <httpErrors existingResponse="PassThrough" />
    
    • Check the path correctly
    • Under wwwroot folder created one folder named public and added the error.html page. Give the same path /public/404.html in web.config
    • Tried to access the page which does not exists, it redirected to the error page

    enter image description here