I want to add custom error pages to my project. I found this post about my problem and i try to implement it.
So :
- i add
404.cshtml
,404.html
,500.cshtml
and500.html
pages - set response status code in added cshtml files
- comment adding
HandleErrorAttribute
to global filters - update my web.config file
But now when i try to go by path http://localhost:120/foo/bar
where my app is on http://localhost:120
i get next page :
Server Error in '/' Application.
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
I set <customErrors mode="Off"
to see what problem is. It was - The resource cannot be found.
which is logical. But when i set <customErrors mode="On"
- i again get Runtime error.
What can cause it and how to solve it?
My config file :
<system.web>
<customErrors mode="Off" redirectMode="ResponseRewrite" defaultRedirect="~/500.cshtml">
<error statusCode="404" redirect="~/404.cshtml"/>
<error statusCode="500" redirect="~/500.cshtml"/>
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="404.html" responseMode="File"/>
<remove statusCode="500"/>
<error statusCode="500" path="500.html" responseMode="File"/>
</httpErrors>
</system.webServer>
IIS version 8.5