By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Frustrations with Error Logging

P: n/a
Hi

From classic ASP, I had a custom error handling situation that was
quite simple. Errors were all redirected to Error.asp. This page would
check 2 settings, EmailErrorMessage and DisplayErrorMessage. If
EmailErrorMessage was true, it would send an email with the error
details. If DisplayErrorMessage was true, it would display the message
on screen. Also, if an Administrator was logged in, it would display
the message as they could then handle it.

Now in .NET this is proving EXTREMELY frustrating.

Please correct me if my logic here is wrong: In the web.config file, I
can add the lines:
<customErrors mode="On" defaultRedirect="/Error.aspx">
<error statusCode="400" redirect="/Error.aspx?err=400" />
<error statusCode="401" redirect="/Error.aspx?err=401" />
<error statusCode="403" redirect="/Error.aspx?err=403" />
<error statusCode="404" redirect="/Error.aspx?err=404" />
<error statusCode="408" redirect="/Error.aspx?err=408" />
<error statusCode="500" redirect="/Error.aspx?err=500" />
<error statusCode="503" redirect="/Error.aspx?err=503" />
</customErrors>

That looks like an elegant and simple solution. BUT, error.aspx won't
have access to the error object as this is effectively a redirect, and
the error object is lost.

Now I've seen that you can ("should") handle your error in the
Global.asax area and then transfer to a simple HTML page. But this is
just stupid. Firstly, I'm filling up my global.asax with error
handling code. Secondly, I can send the email with the error info from
this point, but when I redirect to the error page, I lose the ability
to display the error message on screen to administrators.

SO, I can try putting this into global.asax:
void Application_Error(object sender, EventArgs e)
{
Server.Transfer("/Error.aspx");
}

BUT, when this gets to my error page, this new error object doesn't
have the info I would like. I get the error with:
Exception objError = Server.GetLastError().GetBaseException();

But this doesn't have the error code, or line number, etc. I would
like to (for example) be able to filter out the 404 errors, as these
can be handled with a simple redirect to the home page, as that
content has moved, and it's not worth showing an error page for it.
But I can't do that now!

I don't get this new logic. For example, it's got a property
objError.Source, which gives a result: "System.Web". Of course &(%@
System.Web created the error - it's a website system!!!!!

Why did they take away the very simple and useful Line Number and
Error Number (error code)???

Anyone got a good idea on what to do?
Jul 30 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a


Here is one way to make a helper call.

Create a class.
public class WebPageExceptionWrapper
{

public static void HandleException( Page p , Exception ex ) //by sending
in the Page, you have alot of control for redirects and stuff
{
if(null==p)
{
return;
}

p.Response.Write (ex.Message);

bool redirect = true; //just a crappy way to show you can optionally
redirect.
if(redirect)
{
p.Response.Redirect(http://www.microsoft.com);
}

}
}

then on your aspx.cs files
public void TrySomething()
{

try
{
int i = 0;
int j = 0;
int k = i/j;

}
catch(Exception ex)
{
WebPageExceptionWrapper.HandleException(this.Page , ex);
}

}

Unforunately, I cannot agree with you on the "helpful error numbers".
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!234.entry
Exception Handling is a slightly different mindset (as opposed to
errorhandling in vb/asp terms).
And IMHO is a much better solution.

Follow my blog entry and find the great article by Krzysztof Cwalina.

Good luck on your endeavors.
This is ONE idea. There are others. But I think this is a good "bridge the
gap" idea for you coming from asp.

"sean_walsh" <se**************@hotmail.comwrote in message
news:32**********************************@r66g2000 hsg.googlegroups.com...
Hi

From classic ASP, I had a custom error handling situation that was
quite simple. Errors were all redirected to Error.asp. This page would
check 2 settings, EmailErrorMessage and DisplayErrorMessage. If
EmailErrorMessage was true, it would send an email with the error
details. If DisplayErrorMessage was true, it would display the message
on screen. Also, if an Administrator was logged in, it would display
the message as they could then handle it.

Now in .NET this is proving EXTREMELY frustrating.

Please correct me if my logic here is wrong: In the web.config file, I
can add the lines:
<customErrors mode="On" defaultRedirect="/Error.aspx">
<error statusCode="400" redirect="/Error.aspx?err=400" />
<error statusCode="401" redirect="/Error.aspx?err=401" />
<error statusCode="403" redirect="/Error.aspx?err=403" />
<error statusCode="404" redirect="/Error.aspx?err=404" />
<error statusCode="408" redirect="/Error.aspx?err=408" />
<error statusCode="500" redirect="/Error.aspx?err=500" />
<error statusCode="503" redirect="/Error.aspx?err=503" />
</customErrors>

That looks like an elegant and simple solution. BUT, error.aspx won't
have access to the error object as this is effectively a redirect, and
the error object is lost.

Now I've seen that you can ("should") handle your error in the
Global.asax area and then transfer to a simple HTML page. But this is
just stupid. Firstly, I'm filling up my global.asax with error
handling code. Secondly, I can send the email with the error info from
this point, but when I redirect to the error page, I lose the ability
to display the error message on screen to administrators.

SO, I can try putting this into global.asax:
void Application_Error(object sender, EventArgs e)
{
Server.Transfer("/Error.aspx");
}

BUT, when this gets to my error page, this new error object doesn't
have the info I would like. I get the error with:
Exception objError = Server.GetLastError().GetBaseException();

But this doesn't have the error code, or line number, etc. I would
like to (for example) be able to filter out the 404 errors, as these
can be handled with a simple redirect to the home page, as that
content has moved, and it's not worth showing an error page for it.
But I can't do that now!

I don't get this new logic. For example, it's got a property
objError.Source, which gives a result: "System.Web". Of course &(%@
System.Web created the error - it's a website system!!!!!

Why did they take away the very simple and useful Line Number and
Error Number (error code)???

Anyone got a good idea on what to do?

Jul 30 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.