누구나 DNN 7에서 사용자 정의 오류 처리 경험이 있습니까?DNN 7에서 사용자 정의 오류 처리?
내장 된 로깅은 괜찮지 만 ALL 예외가 발생하면 사용자 정의 전자 메일 보내기를 포함하도록 DNN의 오류 처리 기능을 확장해야합니다. 우리는 Application_Error에 이벤트 리스너를 추가 한 HttpModule을 만들었고 그런 식으로 예외를 이메일로 보냈습니다. 그러나 예외가 전자 메일로 전송 된 후 관리> 사이트 설정의 DNN 속성에 지정된 500 오류 페이지로 일관되게 리디렉션되지 않습니다. 예외 유형에 따라 다른 동작이 있습니다. 일부 예외 (NullReferenceException)로 인해 Application_Error가 발생하고 전자 메일이 보내지지만 리디렉션되지 않으면 다른 (HttpException)이 Application_Error 이벤트가 발생하지 않고 500 페이지로 리디렉션됩니다. Application_Error가 발생하기 전에 DNN에서 이러한 오류를 포착 할 수 있습니까? 이러한 문제를 해결하는 방법에 대한 아이디어가 있습니까? DNN 이미 모든 예외 이메일을 보낼 수 있습니다
/// /// Class for error handling and emailing exceptions to the error distribution list. /// public class ErrorModule : IHttpModule { #region Private Properties /// /// Gets the requested URL. /// /// The requested URL. private string requestedUrl { get { //TODO: create CmsPathTranslationFactory to create ICmsPathTranslator object for 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 the specified application. /// /// The application. public void Init(HttpApplication application) { application.Error += new EventHandler(application_Error); } /// /// Disposes of the resources (other than memory) used by the module that implements . /// public void Dispose() { } #endregion #region Public Methods /// /// Handles the Error event of the application control. /// /// The source of the event. /// The instance containing the event data. public void application_Error(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; // get the last exception Exception exception = application.Server.GetLastError(); if (exception == null) { // exception is null, nothing to send sendErrorMessage(new Exception("Exception is null.")); return; } // get the inner exception if not null if (exception.InnerException != null) { exception = exception.InnerException; } if (exception is HttpException && ((HttpException)exception).GetHttpCode() == 404) { //don't send exception email for 404 } else { sendErrorMessage(exception); } } #endregion #region Private Methods /// /// Sends an email message with the specified error. /// /// The 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 the error email subject based on the specified exception. /// /// The ex. /// The requested URL path. /// System.String. private string getErrorEmailSubject(Exception ex, string requestedPath) { return !string.IsNullOrEmpty(ex.Message) ? string.Concat(requestedPath, " - ", ex.Message) : requestedPath; } #endregion }
이 문제는 좋은 질문입니다. – bflemi3