title: how to Read Ihttpmodule from web.config system.web and system.webServer
body: <p>web.config looks like:</p>
  
  <hr>
  
  <pre><code>   &lt;system.web&gt;
     &lt;httpModules&gt;
    &lt;add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/&gt;
      &lt;/httpModules&gt;
    &lt;/system.web&gt;
       &lt;system.webServer&gt;
       &lt;modules&gt;
      &lt;remove name="DotNetCasClient"/&gt;
      &lt;add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/&gt;
        &lt;/modules&gt;
   &lt;/system.webServer&gt;
  </code></pre>
  
  <p>In C# Code:</p>
  
  <pre><code>  [assembly: PreApplicationStartMethod(typeof(CasClientStart), "Start")]
  
   namespace Dev.CasClient
   {
  
  public static class CasClientStart
  {
  
      /// &lt;summary&gt;
      ///     Starts the application
      /// &lt;/summary&gt;
      public static void Start()
      {
          if( !..... Registered (DotNetCasClient) In Web.config)
          DynamicModuleUtility.RegisterModule(typeof(DotNetCasClient));
  
      }
     }
     }
  </code></pre>
  
  <p>how to Read  httpmodule from web.config ?
  before  Dynamic Register Module,I want check Web.confg at first.</p>
  
  <hr>
  
  <p>my solution,</p>
  
  <pre><code>   // the Final Solution
      public static void Start()
      {
         var IWantReg = typeof(CasClientModule).FullName;
          var Configuration = WebConfigurationManager.OpenWebConfiguration("~");
      if (HttpRuntime.UsingIntegratedPipeline)
      {
          var websermodules = Configuration.GetSection("system.webServer");
  
          var xml = websermodules.SectionInformation.GetRawXml();
  
          XDocument xmlFile = XDocument.Load(new StringReader(xml));
          IEnumerable&lt;XElement&gt; query = from c in xmlFile.Descendants("modules").Descendants("add") select c;
  
          foreach (XElement band in query)
          {
              var attr = band.Attribute("type");
  
              var strType = attr.Value.Split(',').First();
  
              if (strType.ToLower() == IWantReg.ToLower())
                  return;
          }
      }
      else
      {
          object o = Configuration.GetSection("system.web/httpModules");
          HttpModulesSection section = o as HttpModulesSection;
          var models = section.Modules;
  
          foreach (HttpModuleAction model in models)
          {
              if (model.Type.Split(',').First() == IWantReg)
                  return;
          }
      }
  
  
      DynamicModuleUtility.RegisterModule(typeof(CasClientModule));
  
  }
  </code></pre>
  
  <blockquote>
    <p>终于解决了这个问题，分别通过集成与经典格式两种方式。  感谢朋友们的帮助。</p>
  </blockquote>