Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #41 (permalink)  
Old February 8th, 2008, 04:16 PM
Authorized User
 
Join Date: Jun 2006
Location: Lahore, , Pakistan.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much Lee Dumond!
You even cleared up the things that were in my head but I couldn't write them up in the post...
Could you please clear me one more thing? If we hook up this kind of "Exception Handling"(Exception Handling in DAL & BLL, the one you specified),don't we have to then configure the Health Monitoring System which ASP.NET 2.0 provides?

  #42 (permalink)  
Old February 8th, 2008, 05:18 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
quote:Originally posted by tectrix
 Thank you so much Lee Dumond!
You even cleared up the things that were in my head but I couldn't write them up in the post...
Could you please clear me one more thing? If we hook up this kind of "Exception Handling"(Exception Handling in DAL & BLL, the one you specified),don't we have to then configure the Health Monitoring System which ASP.NET 2.0 provides?

Not really. I will say that Health Monitoring in ASP.NET is a good thing to have. It provides a convenient way of persisting error data, and a lot of nice built-in functions, like logging heartbeats, failure audits (invalid login attempts, etc) custom events (like the delete records event in the book), and other stuff. No sense re-inventing the wheel if we already have a system like this in place.

But you could also write your own error-logging logic if you wanted. A good place to do that is in Global.asax. For real simple sites, I sometimes won't even log errors, instead, I'll just have the app send the webmaster an email about the error.

So yes, health monitoring is useful, but it's important to understand that error monitoring, logging and notification isn't the whole story. Trapping exceptions and presenting useful feedback to your users when they happen is the most important thing.

I will also add this -- and this is something a lot of people don't realize -- not every exception is an "error" in the classic sense. It is sometimes useful to throw your own exceptions that wouldn't necessarily be considered "errors" by ASP.NET, but would be violations of your own logic. Like say, for example, you have an scheduling application where someone tries to schedule an appointment for a date in the past. You could throw an ApplicationException in this case, or even your own custom exception that derives from ApplicationException, like MyAppointmentDateException. Then, you can handle it as required.



  #43 (permalink)  
Old February 10th, 2008, 03:45 PM
Authorized User
 
Join Date: Jun 2006
Location: Lahore, , Pakistan.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Lee Dumond, for this complete explanation. You explain very well. When I read ur replies I feel as if I’m reading some book’s article :P
Okay, I’ve this code in my Global.asax to send error details to me . I got this code from some online article and it works fine. Does it hurt if I use this along with Health Monitoring System or should I configure SimpleMailWebEventProvider with SqlWebEventProvider if I want errors/events details be send to me along with being logged in the DB?
void Application_Error(object sender, EventArgs e)
    {
        string strError = "Error in: " + Request.Path +
            "\nUrl: " + Request.RawUrl + "\n\n";

        // Get the exception object for the last error message that occured.
        Exception ErrorInfo = Server.GetLastError().GetBaseException();
        strError += "Error Message: " + ErrorInfo.Message +
            "\nError Source: " + ErrorInfo.Source +
            "\nError Target Site: " + ErrorInfo.TargetSite +
            "\n\nQueryString Data:\n-----------------\n";

        // Gathering QueryString information
        for (int i = 0; i < Context.Request.QueryString.Count; i++)
            strError += Context.Request.QueryString.Keys[i] + ":\t\t" + Context.Request.QueryString[i] + "\n";
        strError += "\nPost Data:\n----------\n";

        // Gathering Post Data information
        for (int i = 0; i < Context.Request.Form.Count; i++)
            strError += Context.Request.Form.Keys[i] + ":\t\t" + Context.Request.Form[i] + "\n";
        strError += "\n";

        if (User.Identity.IsAuthenticated) strError += "User:\t\t" + User.Identity.Name + "\n\n";

        strError += "Exception Stack Trace:\n----------------------\n" + Server.GetLastError().StackTrace +
            "\n\nServer Variables:\n-----------------\n";

        // Gathering Server Variables information
        for (int i = 0; i < Context.Request.ServerVariables.Count; i++)
            strError += Context.Request.ServerVariables.Keys[i] + ":\t\t" + Context.Request.ServerVariables[i] + "\n";
        strError += "\n";

        // Sending error message to administration via e-mail
        System.Web.Mail.SmtpMail.Send("email@domain.com"," email@domain.com", "Error has occured", strError);



    }



  #44 (permalink)  
Old February 11th, 2008, 02:55 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
quote:Originally posted by tectrix


Okay, I’ve this code in my Global.asax to send error details to me . I got this code from some online article and it works fine. Does it hurt if I use this along with Health Monitoring System or should I configure SimpleMailWebEventProvider with SqlWebEventProvider if I want errors/events details be send to me along with being logged in the DB?
It doesn't hurt at all. However, it would be a bit redundant if you were using SimpleMailWebEventProvider to send errors, along with handling the app-level event in Global.asax. Of course, you could configure SimpleMailWebEventProvider to NOT send errors, but to send other stuff, like Audits, Custom Events, and so on; and rely on Application_Error to send the errors.

The advantage of using Global.asax is that it is easier to customize exactly what info you want included in the email, and to format it the way you want. The advantage of using SimpleMailWebEventProvider is that it can notify you of other HM events besides errors, and it's easier to specify exactly what kind of events/errors you want to be notified about and under what conditions.


  #45 (permalink)  
Old February 14th, 2008, 06:44 AM
Authorized User
 
Join Date: Jun 2006
Location: Lahore, , Pakistan.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Lee Dumond! You really healped me clearing my concept about handling and managing Exceptions and Events. Thanks once again.

  #46 (permalink)  
Old February 17th, 2008, 02:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to be careful with Application_Error. It can catch exceptions that occur in various places where some of those objects (in the code above) may be null and you can get further exceptions that prevent the email from being sent. If you use this type of code you should do a lot of checking for nulls also. For example:

Code:
if (Context != null && Context.Request != null)
{
 for (int i = 0; i < Context.Request.QueryString.Count; i++)
   ...
  #47 (permalink)  
Old February 17th, 2008, 09:27 AM
Authorized User
 
Join Date: Jun 2006
Location: Lahore, , Pakistan.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, thanks for pointing this out. I didn't think of this.

  #48 (permalink)  
Old February 18th, 2008, 02:11 PM
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bear in mind that throwing exceptions is expensive. they are best handled in the method in which they occur and an appropriate value/message passed back to the caller.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the image of "The Beer House"? dr_ran ASP.NET 2.0 Basics 0 May 31st, 2008 10:48 AM
About User Profiles in the beer house ssomchai BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 25th, 2008 11:28 PM
The Beer House Arabic Localization nesrine ASP.NET 2.0 Professional 1 February 21st, 2007 12:04 PM
Problem with forum of the beer house kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 31st, 2006 03:33 PM
The Beer House kooltech BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 May 8th, 2006 10:31 PM



All times are GMT -4. The time now is 08:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.