0

Being a newbie to MVC, I tried to implement custom error handling in my demo application. I tried a few steps fro this document Error Handling Document but the custom error page for error 404 is not being shown.

Here is what I have tried so far .

My web.config looks like :

enter image description here

And the FilterConfig.cs looks like :

enter image description here

And here is the custom sample error page page404.html for the initial round of testing :

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <h1>Page is not there dude !!</h1>
    Sorry about this.
</body>
</html>

But still when a request a url which is not configured into my application, I still get the trivial page not found error page.

enter image description here

What am I missing ?

Update

I understand next I have to update the error page to be an .aspx page. But for now I just want the initial version to work.

Please find the web.config below :

<?xml version="1.0"?>

<configuration>

  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <customErrors mode="On">
      <error statusCode="404" redirect="~/Error/page404.html"/> <!--On all 404 pages, show page404.aspx-->
    </customErrors>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>

    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />  
  </handlers>
  </system.webServer>
</configuration>
1
  • Please see the 2nd section of the Custom 404 Error Pages section. Commented Mar 8, 2016 at 15:57

1 Answer 1

2

try to add the block <customErrors> inside <system.web> section ,Like this :

<configuration>
<system.web>
    <customErrors mode="On">
      <error statusCode="404" redirect="~/Error/error.html" />
    </customErrors>
</system.web>
</configuration>

[Update] as per the last screenshot this issue should be appeared if :

  1. customerror mode is off.
  2. statuscode is not matched.

both are not in your web.config , so try iisreset on the server. Also the web.config attached is similar to the one under "view" folder , try web.config under the web application directly

Sign up to request clarification or add additional context in comments.

14 Comments

But the block is under <system.web> only . Have I to change the name of the file .. you mean ?
@StrugglingCoder ,In the screen shot customErrors is under <configuration> section directly , it should be like this (I will update the answer) : <configuration> <system.web> <customErrors mode="On">
I have put it back under <system.web> but still no luck :( . Please see the updated screenshot .
I tried to simulate your case on my machine with visual studio, and it worked fine, but it gives me the same error only in the mentioned two cases in the answer. so I guess it's iisreset could help or if you prefer, you could share web.config file to test with it in my machine
I found something else , the web.config you sent is similar to the one under "view" folder , try web.config under the web application directly.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.