我正在使用asp.net MVC4 + visual studio2012。一切正常,但是只有自定义错误始终在URL上具有 aspxerrorpath 参数。
我已经在 web.config 上配置了自定义错误:
<customErrors mode="On" defaultRedirect="~/Error/Error">
<error redirect="~/Error/Error" statusCode="404" />
<error redirect="~/Error/Error" statusCode="500" />
</customErrors>
我也将错误操作更改为:
public ActionResult Error()
{
Response.Status = "404 Not Found";
Response.StatusCode = 404;
return View();
}
现在将在发生404时发生。我的URL上总是有aspxerrorpath参数。
我尝试将
redirectMode="ResponseRewrite"
添加到customError节点,但是如果添加,则错误将显示运行时异常.....那么,有什么最好的方法来删除aspxerrorpath参数吗?谢谢。
最佳答案
另一个简单的解决方案是针对404错误打开customErrors
文件中的web.config
:
<customErrors mode="On">
<error statusCode="404" redirect="~/home/notfound" />
</customErrors>
并在家庭 Controller 中:
public ActionResult NotFound(string aspxerrorpath)
{
if (!string.IsNullOrWhiteSpace(aspxerrorpath))
return RedirectToAction("NotFound");
return View();
}
关于asp.net-mvc-4 - 使用CustomErrors使用ResponseRewrite删除aspxerrorpath参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22630891/