title: origin 'http://localhost:4200' has been blocked by CORS policy
body: <p>Have an application in angular 7 also has an .net web api solution , when i call an action CORS issue occurs , error follows </p>
  
  <p>Access to XMLHttpRequest at '<a href="http://localhost:57467/UserDetails/GetUserDetails" rel="nofollow noreferrer">http://localhost:57467/UserDetails/GetUserDetails</a>' from origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.</p>
  
  <p>I tried to add CORS fix using using System.Web.Http.Cors in web api but still error occurs .Thanks in advance .Help me out of this problem </p>
  
  <pre><code>     public static class WebApiConfig
       {
             public static void Register(HttpConfiguration config)
               {
          EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
          config.EnableCors(cors);
          // Web API configuration and services http://localhost:80/DemoApp/WebForm1.aspx
          // Configure Web API to use only bearer token authentication.
          config.SuppressDefaultHostAuthentication();
          config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
  
          // Web API routes
          config.MapHttpAttributeRoutes();
  
          config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
      }
  }
  </code></pre>
  
  <p>global.asax.cs</p>
  
  <pre><code>       protected void Application_BeginRequest()
      {
          string[] allowedOrigin = new string[] { "http://localhost:4200", "http://localhost:2052" };
          var origin = HttpContext.Current.Request.Headers["Origin"];
          if (origin != null &amp;&amp; allowedOrigin.Contains(origin))
          {
              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", origin);
              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST");
          }
      }
  </code></pre>
  
  <p>api call from angular </p>
  
  <pre><code>    let headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });
      let options = { headers: headers, crossDomain: true, withCredentials: true };
      return this._http.get(path, options)
          .pipe(map(res =&gt; {
              return JSON.parse(res.toString());
          }),
              catchError(this.handleError)
          );
  </code></pre>