Eventually figured out, in "<httpErrors>
" section, "path" cannot contain "~"! After removing "~" 404 redirection works for me both development/production environment.
The ideal situation we want:
- Disable 404/500 redirection in development mode.
- Enable 404/500 redirection in production mode.
To achieve this, the best practice here is in web.Release.config "enable" the 404/500 redirection, please be aware of "xdt:Transform="Insert"":
<httpErrors errorMode="Custom" existingResponse="Insert" defaultResponseMode="ExecuteURL" xdt:Transform="Insert">
<clear />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL" />
<error statusCode="500" path="/500.aspx" responseMode="ExecuteURL" />
</httpErrors>
So in development environment (i.e. web.debug.config), we can still get the default detailed exception page instead of redirecting to 500:
<httpErrors errorMode="Detailed" existingResponse="Auto" />