转自:http://www.cnblogs.com/DeasonGuan/articles/Hanami.html
404跳转: http://www.cnblogs.com/SALIN/archive/2011/08/25/2152991.html
.net 404 拦截,跳转自定义404(放于Global.asax文件内):
protected void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行,获取错误
Exception error = Server.GetLastError();
if (error != null && error is HttpException){
Response.StatusCode = ((HttpException)error).GetHttpCode();
Server.Transfer(Server.MapPath(Response.StatusCode == 404 ? "~/Home/Error404" : "~/Home/Error"));
}
}
404控制器:
public ActionResult Error404() { return new HttpStatusCodeResult(404, " URL not found ..."); }
public ActionResult Error404() { return HttpNotFound(); }