Reputation: 1842
I have tried to set up a Custom 404 page, and it is redirecting to that URL. However, it's not showing the page it should be. IIS 6
So, I have the web.config setting AND I'm returning a 404 code on the NotFound.aspx page.
Web.config
<customErrors mode="RemoteOnly" defaultRedirect="~/error/Default.aspx">
<error statusCode="404" redirect="~/error/NotFound.aspx" />
</customErrors>
NotFound.aspx.cs
public partial class error_NotFound : Custom.PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
Response.StatusCode = 404;
}
}
You can see here that this:
https://www.mshsaa.org/notapage.aspx
...redirects to this:
https://www.mshsaa.org/error/NotFound.aspx?aspxerrorpath=/notapage.aspx
NOTE This does appear to work correctly on my local machine, but not on live.
NOTE2 I see that there is also an IIS setting for a 404 Error that redirects.
So, what am I doing wrong?
Upvotes: 0
Views: 226
Reputation: 9470
This is working code from my production server.
web.config
<customErrors mode="On" defaultRedirect="/404.aspx" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="/500.aspx" />
</customErrors>
404.aspx.cs
public partial class error_NotFound : Custom.PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
//do something with the exception
Server.ClearError();
Response.StatusCode = 404;
}
}
Upvotes: 0