I see what you're saying. You use Application_Err or to do all of your error
trapping and then redirect from there. Ok, you can do that, but it's defeating
the purpose of the <customErrors >.
Anyway, to determine if the error comes from your code or elsewhere you should
check to see if the Context.Error is an HttpUnhandledEx ception. If so, then
the unhandled exception is something from your code (like a cast error, DBConnection
error, that sort of thing) that occurs at runtime. The Context.Error.I nnerException
tells the real story as to why the error occured.
If it's a typo in the ASPX page, then the error is a HttpException with an
InnerException of HttpCompileExce ption.
So you might code it like this:
protected void Application_Err or(Object sender, EventArgs e)
{
Exception ex = Context.Error;
if (ex is HttpUnhandledEx ception)
{
// my problem
Server.Transfer ("error.aspx ");
}
else if (ex is HttpException)
{
if (ex.InnerExcept ion is HttpCompileExce ption)
{
// typo in ASPX
Server.Transfer ("SendEmailToDe vTeam.aspx");
}
}
}
Though personally I'd find this very tedious to maintain. We discussed this
a couple fo weeks ago on DevelopMentor's listservs:
http://discuss.develop.com/archives/...B&P=R3885&I=-3 http://discuss.develop.com/archives/...B&P=R3787&I=-3
-Brock
DevelopMentor
http://staff.develop.com/ballen I beleive when I use when I use the global.asax on application error
that it does get control when this situation occurs. If possible I
would like to identify it there(in the global.asax). All of the error
handleing is located in one program that is server.transfer ed to.
"Brock Allen" wrote:
Look into the <customErrors > section in web.config -- it allows you
to configure a nice user friendly page that the user will get
redirected to when there are unhandled exceptions in your
application.
http://msdn.microsoft.com/library/de...ary/en-us/cpge
nref/html/gngrfcustomerro rssection.asp
-Brock
DevelopMentor
http://staff.develop.com/ballen Despite our best efforts occasionally in an aspx file, something
like <%=x%> where x is not defined sqeaks by and I get the ugly asp
error message. I want to be able to identify this particular error
and issue a pretty message. I use the global.asax on application
error to handle generalized error handling. I want to be able to
capture and identify the above error.