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
Try using the below code
<customErrors mode="On" >
<error statusCode="404" redirect="~/Error/PageNotFound" />
</customErrors>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.