0

I am trying to redirect user to an controller action while there is any 404 found. Like missing Controller or missing action or bad 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. Even if the URL is valid.This may kill performance during production deployment. Any suggestion or another approach

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

Try using the below code

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