Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 5 HttpErrors + Controller/Action

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!

like image 249
Sergey Shoshin Avatar asked Nov 21 '13 12:11

Sergey Shoshin


People also ask

What is used to handle an error in MVC?

Building Web Applications with ASP.NET Core 3 MVC In ASP.NET, error handling is done using the standard try catch approach or using application events. ASP.NET MVC comes with built-in support for exception handling using a feature known as exception filters.


2 Answers

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).

like image 146
Sergey Shoshin Avatar answered Sep 20 '22 16:09

Sergey Shoshin


Why dont you simply redirect the url for 404

<customErrors mode="RemoteOnly"  defaultRedirect="~/error">
    <error statusCode="404" redirect="~/Error/HttpRequestError" />    
</customErrors
like image 38
Murali Murugesan Avatar answered Sep 23 '22 16:09

Murali Murugesan