Reputation: 365
I'm trying to get the custom 404 page we've built to display instead of the default 404 page created by the server. It works as intended when debugging the application locally, but not when running the application on the server. And their web.config files look exactly the same.
<customErrors mode="On" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>
The weird thing is when anything about the is modified - setting mode to "Off" or "RemoteOnly", changing "~/Error" to just "Error", or removing the section entirely - the result is always the same: I get my nice looking 404 page locally, but not on the server.
When debugging locally, this method executes as intended:
public class ErrorController : BaseController
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult NotFound()
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
ErrorSignal.FromCurrentContext().Raise(new HttpException(404, Request.Url.PathAndQuery + " was not found"));
return View();
}
}
Because it found this route in Global.asax:
routes.MapRoute(
"NotFound",
"{*path}",
new { controller = "Error", action = "NotFound" });
Any and all advice is appreciated.
Upvotes: 3
Views: 5502
Reputation: 365
Problem solved - I went to the guy who manages our IIS settings and had him change the Error Page path for 404s to be a redirect to a URL, that URL being "/Error/NotFound/Index.aspx". But apparently, that's just the equivalent of adding this to the system.webServer section:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error/NotFound" responseMode="ExecuteURL" />
</httpErrors>
Upvotes: 3
Reputation: 30152
Is your iis on the server not running in integrated mode? If so 404s will never hit asp.net What version of iis? Make sure it's not in classic mode.
Upvotes: 0
Reputation: 2830
Sounds to me like the 404 you are getting on the server is because your custom 404 can't be found. Are you able to browse to the custom 404?
Upvotes: 1