title: C# read customHeaders value from web.config
body: <p>I have requirement where I need to read customHeaders value in WCF. Below is sample config file of my application. I need to find programmatically value of "Access-Control-Allow-Origin" key. Please help in achieving the same.</p>
  
  <pre><code>&lt;system.webServer&gt;
  &lt;httpProtocol&gt;
    &lt;customHeaders&gt;
      &lt;add name="X-Content-Type-Options" value="nosniff"/&gt;
      &lt;add name="Access-Control-Allow-Origin" value="http://localhost:4200"/&gt;
      &lt;add name="Access-Control-Request-Method" value="POST,GET,PUT,DELETE,OPTIONS"/&gt;
      &lt;add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type"/&gt;
      &lt;add name="Access-Control-Allow-Credentials" value="true"/&gt;
    &lt;/customHeaders&gt;
  &lt;/httpProtocol&gt;
  </code></pre>
  
  <p></p>
  
  <p>I tried below but it is not working.</p>
  
  <pre><code>Configuration config = serverManager.GetWebConfiguration("Web.Config");
  ConfigurationSection httpProtocolSection = config.GetSection("system.webServer/httpProtocol");
  ConfigurationElementCollection customHeadersCollection = httpProtocolSection.GetCollection("customHeaders");
  foreach(var element in customHeadersCollection)
  {
      Response.Write(element.Attributes[0].Name);
  }
  </code></pre>