1

I am trying to setup a custom 404 error page. In my web.config I have this in my system.web

<customErrors mode="RemoteOnly"> <error statusCode="404" redirect="~/Home/Error404" /> </customErrors> 

I have this method in my HomeController

public ActionResult Error404() { return View(); } 

and this my view

@{ ViewBag.Title = "Error404"; } <h2>Error404</h2> 

My problem is when I goto the URL that does not exist in my website, I do not get my custom page. Is there something I am missing?

1
  • Do you mean when you run the site locally and go to locahost/badurl, you don't see the custom 404 page? Or do you mean on your web host/real site. Commented Feb 19, 2017 at 2:37

1 Answer 1

4

The custom error pages are not enabled for local in your code. So, if you are testing this locally it will not work. Change the web.config entry as below to enable custom error pages locally as well

<customErrors mode="On"> <error statusCode="404" redirect="~/Home/Error404" /> </customErrors> 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.