2009-08-03 7 views
0

Elmah coup toujours Comment filtrer par programmation: Voici mon fichier global:ELMAH Filtrage Programmatically ne fonctionne pas

/// <summary> 
    /// Handles the Filtering event of the ErrorLog control. 
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="Elmah.ExceptionFilterEventArgs"/> instance containing the event data.</param> 
    public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) 
    { 
     Filter(e); 
    } 

    /// <summary> 
    /// Handles the Filtering event of the ErrorMail control. 
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="Elmah.ExceptionFilterEventArgs"/> instance containing the event data.</param> 
    public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) 
    { 
     Filter(e); 
    } 

    /// <summary> 
    /// Filters the specified e. 
    /// </summary> 
    /// <param name="e">The <see cref="Elmah.ExceptionFilterEventArgs"/> instance containing the event data.</param> 
    private void Filter(ExceptionFilterEventArgs e) 
    { 
     Exception exception = e.Exception.GetBaseException(); 
     var httpException = exception as HttpException; 

     if (httpException != null && httpException.GetHttpCode() == 404) 
     { 
      e.Dismiss(); 
     } 

     if (exception is FileNotFoundException || 
      exception is HttpRequestValidationException || 
      exception is ViewStateException || 
      exception is CryptographicException || 
      exception is NodeNullException || 
      exception is SectionNullException || 
      exception is IdentifierNullException || 
      exception is AccessForbiddenException || 
      exception is HttpException) 
     { 
      e.Dismiss(); 
     } 
    } 

    /// <summary> 
    /// Handles the Error event of the Application control. 
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void Application_Error(Object sender, EventArgs e) 
    { 
     bool errorObtained = false; 
     Exception ex = null; 

     try 
     { 
      Exception rawException = Server.GetLastError(); 
      if (rawException != null) 
      { 
       errorObtained = true; 
       if (rawException.InnerException != null) 
       { 
        ex = rawException.InnerException; 
       } 
       else 
       { 
        ex = rawException; 
       } 
      } 
     } 
     catch 
     { 
     } 

     if (errorObtained && ex != null) 
     { 
      if ((HttpContext.Current != null) && (HttpContext.Current.Request != null)) 
      { 
       if (HttpContext.Current.IsCustomErrorEnabled) 
       { 
        Server.Transfer(errorPage, false); 
       } 
      } 
     } 
    } 
+0

Avez-vous vérifié si votre méthode de filtre est appelée du tout en définissant un point d'arrêt? –

+0

NO. C'est pourquoi il ne déclenche pas – user81740

+0

Mon web.config

< /sectionGroup> – user81740

Répondre

0

Je pense que vous devez nommer votre HttpModules comme:

<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /> 
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/> 
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> 

avec les noms exacts spécifiés ci-dessus