MVC 5 HttpErrors + Controller/Action

北城以北 提交于 2020-01-03 08:32:13

问题


How can I change error path to my controller/action with httpErrors?

I have this code:

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

But it doesn't work. Empty page shows and action not entered.

What i do wrong?

P.S. I know about another way to sovle custom page errors. But i want try to use it.

Thanks!


回答1:


I resolve a problem. This code of web.config works:

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

Now entered in ErrorsController/NotFound action(marked with routing atribute ActionName to 404).




回答2:


Why dont you simply redirect the url for 404

<customErrors mode="RemoteOnly"  defaultRedirect="~/error">
    <error statusCode="404" redirect="~/Error/HttpRequestError" />    
</customErrors



回答3:


If Sergey Shoshin's answer does not work.

<httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404"/>
      <error statusCode="404" responseMode="ExecuteURL" path="[optional virtual directories...]/Error/404"/>
</httpErrors>


来源:https://stackoverflow.com/questions/20121176/mvc-5-httperrors-controller-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!