简体   繁体   English

在MVC5中处理404错误

[英]Handling 404 error in MVC5

I am trying to redirect user to an controller action while there is any 404 found. 我尝试将用户重定向到控制器动作,同时找到任何404。 Like missing Controller or missing action or bad URL. 就像缺少控制器,缺少动作或URL错误。 I am using below approach : 我正在使用以下方法:

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="404" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
</httpErrors>

But the issues is my action(pageNotFound) is called every time I request a URL. 但是问题是我每次请求URL时都会调用我的action(pageNotFound)。 Even if the URL is valid.This may kill performance during production deployment. 即使该URL有效,也可能会在生产部署期间降低性能。 Any suggestion or another approach 任何建议或其他方法

Try using the below code 尝试使用以下代码

<customErrors mode="On" >
       <error statusCode="404" redirect="~/Error/PageNotFound" />
</customErrors>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM