I'd like to use a custom error webpage when a timeout, a runtime error message has happened. Is there any way I can use one single webpage and catch the error message?
Based on the sample below, I have to use a different webpage per error. Is that correct? Any other way to accomplish this?
You could use a single generic error and map all of the pages to that, however it can often be useful to use different pages for different types of errors (especially from a debugging standpoint).
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Oops.aspx">
<error statusCode="404" redirect="~/ErrorPages/404.aspx" />
<error statusCode="403" redirect="~/ErrorPages/404.aspx" />
<!-- Other pages here -->
</customErrors>
If you would like to have all of your pages route to a single URL, you can simply leave the additional specific <error> tags off:
<!-- Routes all error pages to the 404.aspx page -->
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/404.aspx">
</customErrors>
or to route all of the pages to an Error.aspx page:
<!-- Routes all error pages to the Error.aspx page -->
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Error.aspx"></customErrors>
For something like this - you would most likely want to create a seperate page for each of the types of errors that you are expecting
(although I am sure that you could parse out which type of error occurred on a generic page)
If you wanted to send an e-mail when an error occurred, then you would put the necessary logic within the Page_Load method of your Error page. If you need additional information on how to send an e-mail through .NET, I'd be glad to assist you.
Upon thinking about it, I believe that you could send QueryString parameters to help detect the type of exception that occured by using a generic page, as shown :
lesponce
Member
108 Points
313 Posts
Custom Web Error Page
Jan 10, 2013 03:40 PM|LINK
I'd like to use a custom error webpage when a timeout, a runtime error message has happened. Is there any way I can use one single webpage and catch the error message?
Based on the sample below, I have to use a different webpage per error. Is that correct? Any other way to accomplish this?
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Oops.aspx">
<error statusCode="404" redirect="~/ErrorPages/404.aspx" />
</customErrors>
so if the error is 403, I should have a 403.aspx page?
Rion William...
All-Star
27782 Points
4589 Posts
Re: Custom Web Error Page
Jan 10, 2013 03:50 PM|LINK
You could use a single generic error and map all of the pages to that, however it can often be useful to use different pages for different types of errors (especially from a debugging standpoint).
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Oops.aspx"> <error statusCode="404" redirect="~/ErrorPages/404.aspx" /> <error statusCode="403" redirect="~/ErrorPages/404.aspx" /> <!-- Other pages here --> </customErrors>If you would like to have all of your pages route to a single URL, you can simply leave the additional specific <error> tags off:
or to route all of the pages to an Error.aspx page:
lesponce
Member
108 Points
313 Posts
Re: Custom Web Error Page
Jan 10, 2013 03:57 PM|LINK
How do I catch the error so I can send it via email?
If I get 403 or 404 and send it the to the same page.... how do I know which error happened?
Rion William...
All-Star
27782 Points
4589 Posts
Re: Custom Web Error Page
Jan 10, 2013 04:05 PM|LINK
For something like this - you would most likely want to create a seperate page for each of the types of errors that you are expecting (although I am sure that you could parse out which type of error occurred on a generic page)
If you wanted to send an e-mail when an error occurred, then you would put the necessary logic within the Page_Load method of your Error page. If you need additional information on how to send an e-mail through .NET, I'd be glad to assist you.
Example using System.Net.Mail
Rion William...
All-Star
27782 Points
4589 Posts
Re: Custom Web Error Page
Jan 10, 2013 04:12 PM|LINK
Upon thinking about it, I believe that you could send QueryString parameters to help detect the type of exception that occured by using a generic page, as shown :
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Oops.aspx"> <error statusCode="404" redirect="~/ErrorPages/Error.aspx?Exception=404" /> <error statusCode="403" redirect="~/ErrorPages/Error.aspx?Exception=403" /> <error statusCode="Example" redirect="~/ErrorPages/Error.aspx?Exception=Example" /> <!-- Other pages here --> </customErrors>and within your Page_Load event, you could determine what type of error occurred :
ManikandanUl...
Participant
850 Points
253 Posts
Re: Custom Web Error Page
Jan 10, 2013 04:26 PM|LINK
Just try this one
Click "…Mark As Answer" if my reply helpful....
lesponce
Member
108 Points
313 Posts
Re: Custom Web Error Page
Jan 10, 2013 04:29 PM|LINK
This should work. Thanks Rion.
Rion William...
All-Star
27782 Points
4589 Posts
Re: Custom Web Error Page
Jan 10, 2013 04:50 PM|LINK
I hope it does. Good luck :)