Alex Rivera | Logout

Forcing custom 404 pages for pages in URL Routing

Asked 2011-06-09T09:10:59.630
16

Coding Platform ASP.NET 4.0 WebForms on IIS7.5

If I request a page blahblah.aspx which does not exist, I get navigated to my custom error page for Page not found Exception. I have implemented URL routing and so I have omitted all my .aspx extensions for routes.

Now, If I type www.mysite.com/blahblah (thats a url without extension) instead of going to my custom error page, it gets redirected to my IIS 404 error page.

What should I do to make my custom error page appear on my site instead of IIS error page?

Edit
Report

1 Answer

5

Assuming you haven't done this already...

Go to IIS, select your website, and choose the option "Error Pages". In there, find the 404 status code, right click and go to "Edit Feature Settings". you can then select "Custom Error pages" and change the "Path Type" to URL "Execute URL" to do some rewriting, or a default redirect page for anything else. Put in your URL as a relative value, and now it should redirect to this url on 404 errors.

Edit: Did a bit of digging, in cases, this config may be locked, if you run the following command, it should remove the lock:

%windir%\System32\inetsrv\appcmd unlock config -section:system.webserver/httperrors

Once that is done, you can edit the url properly.

answered 2011-06-09T09:21:33.750

Your Answer