I've created custom errors for my ASP.NET MVC application and for some reason they only show up on my local machine, but when I deploy my application on remote server the default IIS error pages show up (404 and 500) and I would like to understand why it is so. Here is my app configuration:
web.config
<system.web>
...
<customErrors mode="On" defaultRedirect="~/ServerError">
<error statusCode="404" redirect="~/NotFound" />
</customErrors>
...
</system.web>
Routes configuration
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Error - 404",
"NotFound",
new { controller = "Error", action = "NotFound" }
);
routes.MapRoute(
"Error - 500",
"ServerError",
new { controller = "Error", action = "ServerError" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Error controller:
public class ErrorController : Controller
{
[AllowAnonymous]
public ActionResult ServerError()
{
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return View();
}
[AllowAnonymous]
public ActionResult NotFound()
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View();
}
}
Global.asax
protected void Application_Error(object sender, EventArgs e)
{
Response.TrySkipIisCustomErrors = true;
}
Local machine IIS configuration and remote one look similar, but maybe I've missed something and I have to configure it properly as well.
Thanks for any help.