Original address: http://www.chuchur.com/asp-net-mvc4-404/
There are certainly many ways to define the 404 method. Different ways of showing the form is not the same, the user experience is not the same. The following 22 types of
Method One:
1. Find node <system.web> enable 404 configuration in Web. config
<customerrors defaultredirect= "~/error" mode= "on" redirectmode= "Responseredirect" ><error redirect= "/Error "Statuscode=" 404 "/></customerrors>
2. Define a controllers Error (this follows you), as defined in the action
Public ActionResult Index () {response.status = ' 404 Not Found '; Response.statuscode = 404;return View ();}
This way by default is to add to your URL? aspxerrorpath=/eg:http://localhost/error??aspxerrorpath=/123456 not recommended for trial
Method Two:
Open Global.asax file definition error turn to address (controller/action)
protected void Application_Error (object sender, EventArgs e) { Exception ex = Server.GetLastError (); If (ex is HttpException && (HttpException) ex). Gethttpcode () ==404) { Response.Redirect ("/error"); } }
Custom 404 page in ASP. Mvc4