These are the codes in web.config:
<system.web>
<customErrors mode="Off" >
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="404" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
The above settings will redirect httpError of 404 and 500 only.
But instead of manually add all the error code of 400, 401, 403....etc..etc...
Can we just set it redirect all errors to the same url without typing all the error code?
<error statusCode="400" .....
<error statusCode="401" .....
<error statusCode="403" .....
<error statusCode="404" .....
<error statusCode="xxx" ....
The httpErrors
section has defaultPath
attribute.
<system.webServer>
<httpErrors defaultPath="Error.html" defaultResponseMode="File">
<clear />
</httpErrors>
</system.webServer>
http://www.iis.net/configreference/system.webserver/httperrors
However, I don't use it, because defaultPath
is locked in IIS Express by default. Need to edit %homepath%\Documents\IISExpress\config\applicationHost.config
to unlock it.
<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
<!-- ... -->
</httpErrors>
try this,
add in web.config file.
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
<remove statusCode="500" />
<error statusCode="500" prefixLanguageFilePath="C:\Contoso\Content\errors"
path="500.htm" />
</httpErrors>
</system.webServer>
and
<httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="401" />
<error statusCode="401" path="/Account/Login.aspx" responseMode="ExecuteURL"/>
<remove statusCode="501"/>
<error statusCode="501" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="411"/>
<error statusCode="411" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="403"/>
<error statusCode="403" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
</httpErrors>
and more about this http://www.iis.net/configreference/system.webserver/httperrors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With