Proper reporting of Webform exceptions and other errors

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

MsgBox builds but generates a runtime error. I have seen examples
using MessageBox() but that is not recognized by my version of VB
..NET.

I am now using Response.Write() but this writes to the top of the page
which is inelegant at best. What is the best way to do it?

TIA

Ed
 
Ed said:
MsgBox builds but generates a runtime error. I have seen examples using
MessageBox() but that is not recognized by my version of VB .NET.

I am now using Response.Write() but this writes to the top of the page
which is inelegant at best. What is the best way to do it?

TIA

Ed


You probably need to add a reference to System.Windows.Forms.dll for
MessageBox to work in an ASP.Net project. Not that this is recommended
however...

I would issue a Response.Redirect("SomeErrorPage.aspx").
SomeErrorPage.aspx would need to be passed the exception message via some
means.
 
Thanks, Mike. I tried it but found that the only arg is the error webform. I
am so green at this Web .NET stuff that I have no idea how to communicate
data between Web forms.

I finally did oa Google on Web form MesBox and got lot and lots of hits, so
I am not alone in finding this big disconnect from other styles of Web
development like FrontPage. The answer seems to be embedding a script in the
code behind the form. I did a straight copy of some suggested code to the
place in my VB code where I was doing the Response.Write(). It worked well,
so i think I've got a workable answer. However, it plants seeds of doubt as
to the wonders of the ASP.NET idea. I had been led to believe that it was a
more cabable replacement for the script stuff typically patched into HTML.

Thanks again,

Ed
 
Ed Sowell said:
Thanks, Mike. I tried it but found that the only arg is the error webform. I
am so green at this Web .NET stuff that I have no idea how to communicate
data between Web forms.

I would store the exception as a Session object and retrieve it in the
reporting page. Sorry, I did not mean to imply that Response.Redirect would
take the exception as an argument to the call.

Form 1:
Session ("CurrentError") = theException

Form 2:
dim theException as Exception = Session ("CurrentError")

Mike
 
Ed said:
MsgBox builds but generates a runtime error.

That's a shame - IIRC, ASP used to generate a compile /error/ when you
did this because it's /not/ a Good Thing to do.
Remember: your code is executing within the web server Process, which is
a Windows Service running on your hosting server machine. If you popped
up a dialog, it would appear on the /host/ machine, usually on a
"virtual" desktop that no-one can ever get to see, and would effectively
stall the server process until someone dismissed the dialog. Unless you
have someone on hand 24/7 to click that "OK" button whenever it appears,
you're in trouble.
I have seen examples using MessageBox() but that is not recognized
by my version of VB .NET.

Even if it /were/ recognised, you still shouldn't be using it in a web
application.
I am now using Response.Write() but this writes to the top of the page
which is inelegant at best. What is the best way to do it?

Log the /entire/ Exception (ex.ToString()) into a server-side log file
somewhere, then redirect to a single, user-friendly error page.

HTH,
Phill W.
 
Back
Top