Hi
I am developing an web application in ASP.NET 2.0, C# using Enterprise liabrary 2.0. The application architecture is given below.
the Sample Code for the ApplicationExceptionHandler.cs is as follows
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;
5 using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
6 using System.Web;
7 using System.Collections.Specialized;
8 using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
9
10
11 namespace ExceptionModule
12 {
13 [ConfigurationElementType(typeof(CustomHandlerData))]
14 public class ApplicationExceptionHandler : IExceptionHandler
15 {
16 private const string UNEXPECTED_ERROR = "Unexpected Error!!";
17 public ApplicationExceptionHandler(NameValueCollection ignore)
18 {
19
20 }
21
22
23 #region IExceptionHandler Members
24
25 public Exception HandleException(Exception exception, Guid handlingInstanceId)
26 {
27
28
29 try
30 {
31 if (exception.GetType().Equals(typeof(System.Exception)))
32 {
33 HttpContext.Current.Session["ERROR_MSG"] = exception.Message;
34 }
35
36 }
37 catch (System.Threading.ThreadAbortException ex)
38 {
39 throw ex;
40 }
41 catch (Exception ex)
42 {
43 throw ex;
44 }
45
46 return exception;
47
48 }
49
50 #endregion
51 }
52
53 }
54
the web.config file is given below
1 <?xml version="1.0"?>
2 <!--
3 Note: As an alternative to hand editing this file you can use the
4 web admin tool to configure settings for your application. Use
5 the Website->Asp.Net Configuration option in Visual Studio.
6 A full list of settings and comments can be found in
7 machine.config.comments usually located in
8 \Windows\Microsoft.Net\Framework\v2.x\Config
9 -->
10 <configuration>
11 <configSections>
12 <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
13 <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
14 <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
15 </configSections>
16 <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
17 <listeners>
18 <add fileName="trace.log" header="----------------------------------------" footer="----------------------------------------" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="FlatFile TraceListener"/>
19 </listeners>
20 <formatters>
21 <add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter"/>
22 </formatters>
23 <categorySources>
24 <add switchValue="All" name="General">
25 <listeners>
26 <add name="FlatFile TraceListener"/>
27 </listeners>
28 </add>
29 </categorySources>
30 <specialSources>
31 <allEvents switchValue="All" name="All Events"/>
32 <notProcessed switchValue="All" name="Unprocessed Category"/>
33 <errors switchValue="All" name="Logging Errors & Warnings">
34 <listeners>
35 <add name="FlatFile TraceListener"/>
36 </listeners>
37 </errors>
38 </specialSources>
39 </loggingConfiguration>
40 <exceptionHandling>
41 <exceptionPolicies>
42 <add name="Exception Policy">
43 <exceptionTypes>
44 <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None" name="Exception">
45 <exceptionHandlers>
46 <add type="ExceptionModule.ApplicationExceptionHandler, ExceptionModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Custom Handler"/>
47 </exceptionHandlers>
48 </add>
49 </exceptionTypes>
50 </add>
51 </exceptionPolicies>
52 </exceptionHandling>
53 <appSettings/>
54 <system.web>
55 <!--
56 Set compilation debug="true" to insert debugging
57 symbols into the compiled page. Because this
58 affects performance, set this value to true only
59 during development.
60 -->
61 <compilation debug="true">
62 <assemblies>
63 <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
64 <add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
65 </assemblies>
66 </compilation>
67 <!--
68 The <authentication> section enables configuration
69 of the security authentication mode used by
70 ASP.NET to identify an incoming user.
71 -->
72 <authentication mode="Windows"/>
73 <!--
74 The <customErrors> section enables configuration
75 of what to do if/when an unhandled error occurs
76 during the execution of a request. Specifically,
77 it enables developers to configure html error pages
78 to be displayed in place of a error stack trace.
79
80 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
81 <error statusCode="403" redirect="NoAccess.htm" />
82 <error statusCode="404" redirect="FileNotFound.htm" />
83 </customErrors>
84 -->
85 </system.web>
86 </configuration>
87
I was used the Custom Handler in the exception handling block.
Here my doubt is if any exception occured i would like to show a alert box (jquery alert box or equlant) with the exception details.
I know how to create the jquery alert box. but i have some doubt how to invoke the alert box when the exception occured.
Is there any thing needs to be write in ApplicationExceptionHandler.cs?
please tell me any good solution.
Please ask me if these detiails are not sufficient.