onTheInternet
onTheInternet

Reputation: 7263

Custom 404 not displaying

I have a webforms project that I've made a custom 404 page for.

I've written my redirect in my web.config but it doesn't seem to be working.

Here is the code

<customErrors mode="On" redirectMode="ResponseRedirect">
  <error statusCode="404" redirect="~/404.aspx"/>
</customErrors>

When I visit localhost:(port number)/about I'm taken to the about page. When I visit the same thing but spell 'about' incorrectly, I'm taken to the default 404 page

default 404

What am I missing?

Upvotes: 2

Views: 187

Answers (1)

krlzlx
krlzlx

Reputation: 5832

Custom errors handles aspx pages. You can remove/comment your customErrors section and use httpErrors like this instead:

<system.webServer>
    <httpErrors existingResponse="Replace" errorMode="Custom">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" path="404.aspx" responseMode="Redirect" />
    </httpErrors>
</system.webServer>

Reference: HTTP Errors

Upvotes: 2

Related Questions