Introduction:
Here I will explain how to set custom error page in web.config in asp.net 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 customErrors in web.config file in asp.net we can display or redirect to custom error page whenever error throws in application.
Description:
In previous articles I explained jQuery show session timeout message before session expires, asp.net master page menu control example, asp.net integrate facebook login to website, asp.net detect browser refresh to avoid events fire again, asp.net set session timeout in web.config, iis, Display time like facebook/twitter like 1 minute ago, hour ago, use of using statement in c# and many articles relating to asp.net, css, c#, vb.net and jQuery. Now I will explain how to set / display / redirect to custom error page in asp.net in case of non-existing pages.
In previous articles I explained jQuery show session timeout message before session expires, asp.net master page menu control example, asp.net integrate facebook login to website, asp.net detect browser refresh to avoid events fire again, asp.net set session timeout in web.config, iis, Display time like facebook/twitter like 1 minute ago, hour ago, use of using statement in c# and many articles relating to asp.net, css, c#, vb.net and jQuery. Now I will explain how to set / display / redirect to custom error page in asp.net in case of non-existing pages.
To
set custom error page in web.config in asp.net
or redirect to default page in case if there is error in asp.net
web application we need to write the code like as shown below
<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>
|
By
setting above properties in web.config file automatically it will redirect to
custom error page in our application whenever it throws “404” error.
Same
way we need to set properties in web.config file for following errors also.
- 400
Error (Bad request)
- 401
Error (Unauthorized)
- 403
Error (Forbidden)
- 404
Error (Not found)
- 500
Error (Internal server error)
Here we
used “404.aspx” page in your case you
need to give your custom error page to redirect in your application.
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
1 comments :
Awesome You are and awesome is your post,Keep going guys. Your post are really helpful to all of them who follows you.
I am great following of you i noted down all of your post what you post in FB and Here.
Note: Only a member of this blog may post a comment.