Sample in VB and ASP.NET for the notifying the user scenario

Topics: Exception Handling Application Block
Aug 13, 2009 at 6:04 PM

Hi,

Can someone be so kind as to provide me a code example of a VB 2008 and ASP.NET 3.5 for the notifying the user scenario? I am trying to understand how to create a more complex scenario in ASP.NET but I am newbie. My ultimate objective is to be able to log a ticket notification into Ontime 2009(www.axasoft.com).

Thanks.

Borja

Aug 14, 2009 at 2:59 AM

Hi, I'm not familiar with Ontime 2009 so I can't give you a sample code.  But just to give you an idea, there is no built-in tracelistener for this in Enterprise Library so you would have to create a custom tracelistener for this.  So the ease of complexity of writing it would really depend on the API for logging to wherever you're supposed to log it.  Here is how a custom tracelistener looks like:

(This is also included in the documentation)

<ConfigurationElementType(GetType(CustomTraceListenerData))> _
Public Class DebugTraceListener
  Inherits CustomTraceListener
Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, _
       ByVal eventType As TraceEventType, ByVal id As Integer, ByVal data As Object)
  If (TypeOf data Is LogEntry) And Me.Formatter IsNot Nothing Then
    WriteLine(Me.Formatter.Format(DirectCast(data, LogEntry)))
  Else
    WriteLine(data.ToString())
  End If
Public Overrides Sub Write(ByVal message As String)
  'Ontime 2009 logging codes
End Sub

Public Overrides Sub WriteLine(ByVal message As String)
  'Ontime 2009 logging codes
End Sub

Basically, you will just put your actual codes for logging in Ontime 2009 in the Write/WriteLine methods.  It depends on whatever logic you place in the TraceData method. 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 14, 2009 at 9:36 AM
Hi Sarah, Thanks a lot for the information. I get the idea. I also want to display a custom exception to the user when the actual exception occurs. I understand that this is the "notifying the user" scenario. The samples in EL 4.1 is written for a Winform applications. I need to do the equivalent for ASP.NET. Do you have an example for this scenario in ASP.NET? I assume I need to work work in global.asax and that I need to create a text formatter for ASP.NET, but before doing a trial and error proof of concept I prefer to look at some example that can guide me. Thanks again for your help. Borja
Aug 17, 2009 at 5:58 AM

Oh, I see, I didn't get that the notification was for notifying when an exception occurs.  You need not create a text formatter, you can use the built-in text formatter in entlib.  There's not much difference using EHAB in winforms and web apps.  But yes, you can put in the exceptionhandling code in global.asax so as to be able to handle all exceptions which occurs in your web app.  If you could describe how exactly would you like the user to be notified, I would be able to give you a more detailed answer.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 17, 2009 at 8:39 AM
Sure. Here is the scenario for the ASP.NET application: 1. An exception ocurrs in the web application. 2. The system generates an incident ticket. Here is where I would also have to create a custom tracelistener to be able to send detail of the exception to Ontime 2009 system. 3. The user is prompted with a message saying "An Application error has ocurred. An incident ticket (12345678) was generated. Please contact with the administrator for further detail". 4. The administrator is notifies via email of the incident number so that it can track it in OnTIME 2009. Let me know if you need more detail or further explanation. Thanks Sarah! Borja
Aug 17, 2009 at 10:22 AM

Ah, I think you should determine if there is a way to execute a javascript in the Application_Error event in the global.asax file because it is the easiest place to put your exception handling codes.  I'm not very familiar with javascripts.  You can also consider redirecting the user to a custom error page (http://entlib.codeplex.com/Thread/View.aspx?ThreadId=42926).

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com