title: Enable CORS in Sharepoint 2013
body: <p>I need to make CORS from/to various Sharepoint domains, and of course handle the OPTIONS preflight request.
  After a lot of research I found that <a href="https://stackoverflow.com/a/32351283/5491136">this</a> solution is (almost) the best for my needs.
  Modify global.asax let you handle more than one domain with credentials passed, and the OPTIONS preflight request.</p>
  
  <p>The bad side is that after applying it as suggested, you can't login in Sharepoint Designer anymore.</p>
  
  <p>I modified global.asax as below, CORS are ok, but Sharepoint Designer no.</p>
  
  <pre><code>public void Application_BeginRequest(object sender, EventArgs e) 
  {
  string httpOrigin = Request.Params["HTTP_ORIGIN"];
  if (httpOrigin != null) 
  {   
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", httpOrigin);
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-RequestDigest");
      HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");
  
      if (Request.HttpMethod == "OPTIONS")
      {
          HttpContext.Current.Response.StatusCode = 200;
          var httpApplication = sender as HttpApplication;
          httpApplication.CompleteRequest();
      }
  }    
  }
  </code></pre>
  
  <p>I read with Fiddler the request that Sharepoint Designer does and there's not the header 'Origin' so I don't know where's it fails.
  When I try to login in Sharepoint Designer, I get always 401 as response.</p>
  
  <p>Is there someone that knows how to resolve? Thanks</p>