Error Handling Question(1)

A

A.M

Hi,

I have this code in my web.config:

<customErrors mode="On" defaultRedirect="~/ErrorPages/ErrorApp.aspx">
<error statusCode="400" redirect="~/ErrorPages/Error.aspx" />
<error statusCode="401" redirect="~/ErrorPages/Error.aspx" />
<error statusCode="403" redirect="~/ErrorPages/Error.aspx" />
<error statusCode="404" redirect="~/ErrorPages/Error.aspx" />
<error statusCode="408" redirect="~/ErrorPages/Error.aspx" />
<error statusCode="500" redirect="~/ErrorPages/Error.aspx" />
<error statusCode="503" redirect="~/ErrorPages/Error.aspx" />
</customErrors>

Is there any way that inside Error.aspx code I can find what was the actual
error number?

Thanks,
Al
 
B

bruce barker

<customErrors mode="On" defaultRedirect="~/ErrorPages/ErrorApp.aspx">
<error statusCode="400" redirect="~/ErrorPages/Error.aspx?err=400" />
<error statusCode="401" redirect="~/ErrorPages/Error.aspx?err=401" />
<error statusCode="403" redirect="~/ErrorPages/Error.aspx?err=403" />
<error statusCode="404" redirect="~/ErrorPages/Error.aspx?err=404" />
<error statusCode="408" redirect="~/ErrorPages/Error.aspx?err=408" />
<error statusCode="500" redirect="~/ErrorPages/Error.aspx?err=500" />
<error statusCode="503" redirect="~/ErrorPages/Error.aspx?err=503" />
</customErrors>

string err = Request.QueryString["err"];


-- bruce (sqlwork.com)
 
S

Steven Cheng[MSFT]

Hi Al,

As for getting the Error Code, currently I haven't found any buildin api
which can directly retrieve the unhandled error's error code(in fact, the
error code is something in the http header). I think Bruce's suggestion
that use the appended querystring to represent the error code is a good
solution:
<customErrors mode="On" defaultRedirect="~/ErrorPages/ErrorApp.aspx">
<error statusCode="400" redirect="~/ErrorPages/Error.aspx?code=400" />
<error statusCode="401" redirect="~/ErrorPages/Error.aspx?code=401" />

In addition, since not every unhandled error has error code, because some
are throwed by the ASP.NET runtime exception. If you want to get the
detailed info of the unhandled exception, you need to manually use
Server.Transfer to forward the request to your CustomError page(error.aspx)
manually and use SErver.GetLastError() in the custom error page to get the
exception infos. If not, these error info will be cleared since a new
request is started.

Also, here are the former threads which discussing on this problem:

http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&threadm=$Ey
uIys6DHA.568%40cpmsftngxa07.phx.gbl&rnum=3&prev=/groups%3Fhl%3Dzh-CN%26lr%3D
%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dcustom%2Berror%2Bsteven%2Bcheng

http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&threadm=uxxvF
qIDEHA.2300%40cpmsftngxa06.phx.gbl&rnum=6&prev=/groups%3Fhl%3Dzh-CN%26lr%3D%
26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dcustom%2Berror%2Bsteven%2Bcheng

Hope also helps. Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Al,

Have you had a chance to check out the suggestions in the last reply or
have you got any further ideas on this issue? If you have anything unclear
or if there're anything else we can help, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error Handling 2
Frustrations with Error Logging 1
HTTP Error 404 1
CustomErrors! What is going on? 0
CustomError Problem 4
customErrors 1
<customErrors 3
Question regarding detecting 404 Not Found 2

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top