title: Remove Access-Control-Allow-Origin defined in web.config with ASP.NET
body: <p>We have a definition in web.config to set Access-Control-Allow-Origin header for all requests to one predefined server. like this:</p>
  
  <pre><code>&lt;customHeaders&gt;
      &lt;add name="Access-Control-Allow-Origin"value="http://constantServer.com" /&gt;
      &lt;add name="Accept-Bytes" value="none" /&gt;
  &lt;/customHeaders&gt;
  </code></pre>
  
  <p>there are some cases we need to allow access to different server to a specific resource. we check the origin and set the Access-Control-Allow-Origin by code, like this:</p>
  
  <pre><code>Response.AddHeader("Access-Control-Allow-Origin", origin);
  Response.AddHeader("Access-Control-Allow-Credentials", "true");
  </code></pre>
  
  <p>The problem is that the browser get multiple values for the Access-Control and its not allowed it.</p>
  
  <p>We want to remove by code the header that was defined in the web.config in cases that we need to allow it for different origin.</p>
  
  <p>I tried to remove it at the global.asax in the Application_PreSendRequestHeaders event, but i didnt find this header there.(its seems that this header is being added after this event)</p>
  
  <p>Thanks</p>