how to Set Custom Error Page in Web.Config?

Let me explain how to set custom error page in web.config or display custom error page in asp.net in case URL pattern not matched or asp.net redirect to default error page in case non existing pages. By enabling custom Errors in web.config file we can display or redirect to custom error page whenever error throws in application.

<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="404.aspx" />
</customErrors>
</system.web>

 

<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>

Leave a Reply

Your email address will not be published. Required fields are marked *