Stan
Stan

Reputation: 26501

customErrors in web.config 404 works, 404.0 does not

I have set up custom 404 and it works. But when I try to access some file that does not exist it shows good ol' ASP.NET 404.0 error page.

I've tried to add <error statusCode="404.0" redirect="/notfound/?" /> but it does not work since statusCode should be integer.

Example

http://localhost:123/das/dsagfdsa will redirect to http://localhost:123/notfound/? http://localhost:123/das/dsagfdsa.png will stay and show 404.0 error.

Custom Errors section

<customErrors mode="On" redirectMode="ResponseRedirect" defaultRedirect="/notfound/?">
    <error statusCode="404" redirect="/notfound/?" />
</customErrors>

Question

How do I make sure it will redirect to /notfound/ not only on wrong page requests but also on wrong file requests?

Upvotes: 0

Views: 1352

Answers (1)

Scott
Scott

Reputation: 13921

You have to configure this in IIS. By default, only specific files will get routed through the ASP.NET framework, otherwise IIS will handle it (configured as shown below in the 'Error Pages' section of IIS).

Alternatively, you could configure ASP.NET to handle other file types as well. For more info on this, read about Handler Mappings.

enter image description here

Upvotes: 1

Related Questions