dotnetnuke - Custom error handling in DNN 7? -


anyone here have experience custom error handling inside dnn 7?

the built in logging fine, company has need extend dnn's built in error handling include sending custom emails when all exceptions occur. created httpmodule added event listener on application_error, , have been emailing exceptions way. however, after exception emailed, not being consistently redirected specified 500 error page set in dnn's properties under admin > site settings. have different behavior depending on exception type. exceptions (nullreferenceexception) result in application_error firing , email being sent no redirection, others (httpexception) result in redirect 500 page without application_error event being fired. possible in dnn catching these errors before application_error fires, , ideas on how fix these issues?

here httpmodule added web.config:

      ///      /// class error handling , emailing exceptions error distribution list.     ///      public class errormodule : ihttpmodule {          #region private properties          ///          /// gets requested url.         ///          /// requested url.         private string requestedurl {             {                 //todo: create cmspathtranslationfactory create icmspathtranslator object getting requested url path                 return !string.isnullorempty(httpcontext.current.items["urlrewrite:originalurl"].tostring()) ?                     new uri(httpcontext.current.items["urlrewrite:originalurl"].tostring()).absolutepath : httpcontext.current.request.url.absolutepath;             }         }          #endregion          #region ihttpmodule members          ///          /// initializes specified application.         ///          /// application.         public void init(httpapplication application) {             application.error += new eventhandler(application_error);         }          ///          /// disposes of resources (other memory) used module implements .         ///          public void dispose() { }          #endregion          #region public methods          ///          /// handles error event of application control.         ///          /// source of event.         ///  instance containing event data.         public void application_error(object sender, eventargs e) {             httpapplication application = (httpapplication)sender;              // last exception             exception exception = application.server.getlasterror();              if (exception == null) {                 // exception null, nothing send                 senderrormessage(new exception("exception null."));                 return;             }              // inner exception if not null             if (exception.innerexception != null) {                 exception = exception.innerexception;             }              if (exception httpexception && ((httpexception)exception).gethttpcode() == 404) {                 //don't send exception email 404             }             else {                 senderrormessage(exception);             }         }          #endregion          #region private methods          ///          /// sends email message specified error.         ///          /// exception.         private void senderrormessage(exception ex) {             using (mailmessage message = new mailmessage()) {                 message.to.add(new mailaddress(configurationmanager.appsettings["erroremailtoaddress"]));                 message.replytolist.add(new mailaddress(configurationmanager.appsettings["erroremailreplytoaddress"]));                 message.from = new mailaddress(configurationmanager.appsettings["erroremailfromaddress"], environment.machinename);                 message.subject = geterroremailsubject(ex, requestedurl);                 message.body = ex.tostring();                 message.priority = mailpriority.high;                  using (smtpclient client = new smtpclient()) {                     client.host = configurationmanager.appsettings["smtpserver"];                     client.send(message);                 }             }         }          ///          /// gets error email subject based on specified exception.         ///          /// ex.         /// requested url path.         /// system.string.         private string geterroremailsubject(exception ex, string requestedpath) {             return !string.isnullorempty(ex.message) ? string.concat(requestedpath, " - ", ex.message) : requestedpath;         }          #endregion      } 

dnn can send emails every exception already. can set in event log, editing types of events, , configuring email options.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -