locked
Custom httpErrors in web.config RRS feed

  • Question

  • User-173651909 posted

    I need to configure custom error pages (404/511 etc) in my MVC app running in Azure. Currently I have a directory in the root of the project containing the custom views (~/Errors/404.cshtml) and below is the code I'm using which I've got from various articles.

    <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
          <remove statusCode="400" subStatusCode="-1" />
          <error statusCode="400" responseMode="ExecuteURL" path="~/Errors/400.cshtml" />
          <remove statusCode="401" subStatusCode="-1" />
          <error statusCode="401" responseMode="ExecuteURL" path="~/Errors/401.cshtml" />
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" responseMode="ExecuteURL" path="~/Errors/404.cshtml" />
          <remove statusCode="500" subStatusCode="-1" />
          <error statusCode="500" responseMode="ExecuteURL" path="~/Errors/500.cshtml" />
          <remove statusCode="503" subStatusCode="-1" />
          <error statusCode="503" responseMode="ExecuteURL" path="~/Errors/503.cshtml" />
          <remove statusCode="508" subStatusCode="-1" />
          <error statusCode="508" responseMode="ExecuteURL" path="~/Errors/508.cshtml" />
          <remove statusCode="511" subStatusCode="-1" />
          <error statusCode="511" responseMode="ExecuteURL" path="~/Errors/511.cshtml" />      
        </httpErrors>
    </system.webServer>

    Any ideas as to why it's not picking up the pages? If I try to simulate a 404 by entering an non-existant url (for example www.mywebsite.com/fsdnkjsndfk) then it displays a blank page.

    Thanks in advance
    Adam

    Monday, March 21, 2016 10:12 AM

Answers

  • User-646145796 posted

    Hi,

    As my test, a blank page means that your application failed to find the error page. Please pay attention to your path. And try code below:

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

    Please remove “~”. It works on my side. Hope it helps.

    Best Regards,

    Jambor

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 22, 2016 3:02 AM