Ich habe ein Problem mit dem HTTP-Fehler 404.0 - nicht gefunden. Ich habe dieCatch 404 Fehler in MVC4
in der Web.Config eingeschaltet. Aber das Problem existiert immer noch. Ich habe auch versucht, diese Lösung (Aber es nie erreicht die Methode):
protected void Application_Error()
{
var exception = Server.GetLastError();
var httpException = exception as HttpException;
Response.Clear();
Server.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "Errors";
routeData.Values["action"] = "General";
routeData.Values["exception"] = exception;
Response.StatusCode = 500;
if (httpException != null)
{
Response.StatusCode = httpException.GetHttpCode();
switch (Response.StatusCode)
{
case 403:
routeData.Values["action"] = "HttpError404";
break;
case 404:
routeData.Values["action"] = "HttpError404";
break;
}
}
IController errorsController = new ErrorController();
var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
errorsController.Execute(rc);
}
zur Verfügung gestellt von @Darin Dimitrov
Dies ist der Controller:
public class ErrorController : Controller
{
public ActionResult HttpError404(string error)
{
ViewData["Title"] = "Sorry, an error occurred while processing your request. (404)";
ViewData["Description"] = error;
return View("Index");
}
public ActionResult HttpError500(string error)
{
ViewData["Title"] = "Sorry, an error occurred while processing your request. (500)";
ViewData["Description"] = error;
return View("Index");
}
public ActionResult General(string error)
{
ViewData["Title"] = "Sorry, an error occurred while processing your request.";
ViewData["Description"] = error;
return this.View();
}
Dieser Artikel ist auch hilfreich für die Bereitstellung auf verschiedenen Hosts: http://stackoverflow.com/q/1706934/964043 – dmarietta