I am trying to create a 404 error page, and currently I have all of the following / have tried all of the following to try to accomplish this. When the user enters:
http: //name/something.aspx
It works as intended. But if the user enters:
http: // name / NotAFile
without .aspx, then IIS7 takes matters into my own hands, and I get the excellent error page that IIS7 comes with. The goal is that the site only redirects a 404 status code (not 200 or a 302 redirect). I tried in web configuration with:
<customErrors mode="On" defaultRedirect="~/error/Default.aspx redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/error/NotFound.aspx" />
</customErrors>
This works for a URL with the extension .aspx, but not for the extension. Same thing with this approach in global.asax
void Application_Error(object sender, EventArgs e)
{
var serverError = Server.GetLastError() as HttpException;
if (serverError != null)
{
if (serverError.GetHttpCode() == 404)
{
Server.ClearError();
Server.Transfer("~/error/NotFound.aspx");
}
Server.Transfer("~/error/Default.aspx");
}
}
:( , -:
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
, ...
! !