MVC 5 HttpErrors + controller / action

How can I change the path to my controller / action using httpErrors ?

I have this code:

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

But that will not work. Blank page display and action not entered.

What am I doing wrong?

PS I know about another way to handle custom page errors. But I want to try using it.

Thanks!

+7
asp.net-mvc asp.net-mvc-5
source share
3 answers

I solve the problem. This web.config code works:

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

ErrorsController / NotFound is now in effect (marked with the Routing attribute ActionName up to 404).

+12
source

Why don't you just redirect the url to 404

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

If the answer of Sergei Shoshin does not work.

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

All Articles