我当前的错误处理网址看起来很丑:
http://localhost:65089/Error/NotFound?aspxerrorpath=/Foo
宁可有类似的东西:
http://localhost:65089/Error/NotFound
网络配置代码
<system.web>
<customErrors mode="On" defaultRedirect="~/Error/Unknown">
<error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>
错误控制器
public class ErrorController : Controller
{
//
// GET: /Error/
public ActionResult Unknown()
{
return View();
}
public ActionResult NotFound()
{
return View();
}
}
提前致谢!
答案 0 :(得分:0)
您可以修改Global.asax中的Application_Error方法:
protected void Application_Error(object sender, EventArgs e)
{ Exception ex = Server.GetLastError();
if(ex is HttpException && ((HttpException)ex).GetHttpCode()==404)
{
Response.Redirect("/Error/NotFound");
}
}