0

I am developping an Asp.NET web application with visual studio 2015 and running it under IIS Express. I want to add a custom error page to it.

First, in the web.config file, I added customErrors markup under the system.web section. But it didn't seem to have any effect.

<customErrors mode="On" defaultRedirect="/Error.aspx">
   <error statusCode="404" redirect="/Error.aspx" />
</customErrors>

So I added an httpErrors markup under system.webServer. And it showed me a blank page.

<httpErrors existingResponse="PassThrough" />

So I changed the above httpErrors markup by this one :

<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" defaultPath="/Error.aspx">
  <clear/>
  <error path="/Error.aspx" responseMode="ExecuteURL" statusCode="404"/>
</httpErrors>

And it showed me the "lock violation" error. I Tried to remove ,defaultPath in the applicationHost.config file, rebooted the computer, but the same error appears

Even in Global.asax, the Application_Error is not fired in the case of some error like 404.

Does someone have any clue ?

Edit : I tried to do the same thing in a new solution : So I created a new web application - Blank webforms template. Same result. But when I created a new web application - Blank MVC solution, it worked.

Is there any difference in the config between webforms and mvc? Is someone else have the same issue whith the webforms template ?

2
  • How is your config in App pool and site at IIS ? Commented Aug 15, 2016 at 16:17
  • I am using IIS Express. So I'm not doing any server configuration Commented Aug 15, 2016 at 16:21

1 Answer 1

0

I was able to redirect to error page. I tried this in my current MVC project. Below is excerpt of what i did

  1. Used existing error page in my solution under Views/Shared/Error.cshtml
  2. Used your custom errors parameters

<customErrors mode="On" defaultRedirect="~/Views/Shared/Error.cshtml"> <error statusCode="404" redirect="~/Views/Shared/Error.cshtml" /> </customErrors>

  1. Threw 404 purposefully in my Index.cshtml

@Response.StatusCode=404 @Response.End()

Hint: Please try to see the path and how you are testing 404 error

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

1 Comment

I have my error page named Error.aspx under the root of the server so i set defaultRedirect="/Error.aspx" (also tried defaultRedirect="~/Error.aspx") and to test the 404 i just write in the address bar a URL pointing to a non existing page

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.