Reputation: 1741
I am running into a situation,
My custom 404 page works just fine with URL that has extensions.
http://www.space.ca/ssss.aspx A custom page URL serves up as intended,
however, if you try the link without the .aspx extension http://www.space.ca/ssss
it goes to the IIS default page. Any idea on why?
This is my configuration , inside system.webserver
<httpErrors>
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/errors/404.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/errors/500.aspx" responseMode="ExecuteURL" />
</httpErrors>
Upvotes: 1
Views: 1243
Reputation: 835
This works for me.
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL">
<clear />
<error statusCode="404" path="~/error404.aspx" responseMode="Redirect" />
</httpErrors>
Upvotes: 0
Reputation: 262
I know that this was posted quite a while ago, however this may help others...
I had the same issue and it was mainly down to having '~' within the path values, sadly this is not what your problem but if you follow the following then you should be okay...
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="401" redirect="~/Errors/Unauthorized.aspx" />
<error statusCode="403" redirect="~/Errors/Forbidden.aspx" />
<error statusCode="404" redirect="~/Errors/PageNotFound.aspx" />
<error statusCode="500" redirect="~/Errors/ServerError.aspx" />
<error statusCode="501" redirect="~/Errors/ServerError.aspx" />
</customErrors>
<httpErrors errorMode="Custom">
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<error statusCode="401" path="/Errors/Unauthorized.aspx" responseMode="ExecuteURL" />
<error statusCode="403" path="/Errors/Forbidden.aspx" responseMode="ExecuteURL" />
<error statusCode="404" path="/Errors/PageNotFound.aspx" responseMode="ExecuteURL" />
<error statusCode="500" path="/Errors/ServerError.aspx" responseMode="ExecuteURL" />
<error statusCode="501" path="/Errors/ServerError.aspx" responseMode="ExecuteURL" />
</httpErrors>
Of course you only need to added entries for those status codes you wish to create a custom page for. Also remember that httpErrors should be placed in the section, and the customErrors within the section.
You could add the customErrors section in as this handles managed code. httpErrors section will handle errors for all content.
Please also note one final thing...When you are testing on the local machine the default for both ASP.NET and HTTP errors is to show detailed information on the local browser. You will need to set customErrors mode="On" AND httpErrors errorMode="Custom" in order to see the custom errors on the local machine.
More information can be found here: http://www.iis.net/ConfigReference/system.webServer/httpErrors
Upvotes: 2