title: Enable CORS for MVC and AngularJS
body: <p>I have an IONIC/AngularJS application from which I have to call my ASP.NET MVC controller method i.e <strong>Login</strong>. It works with fine with <strong>$http.get()</strong> but when I use <strong>$http.post()</strong> or <strong>$http({method: 'POST'})</strong> it returns an error. The error is (for Chrome):</p>
  
  <blockquote>
    <p>Response to preflight request doesn't pass access control check: No
    'Access-Control-Allow-Origin' header is present on the requested
    resource</p>
  </blockquote>
  
  <p>I have enabled CORS for Server by following the answer to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/27218240/cors-in-asp-net-mvc5">CORS in ASP .NET MVC5</a></p>
  
  <p>I also included nuget package to enable CORS, but this didn't solve my problem. I also tried adding the following in Angular's POST request:</p>
  
  <pre><code>$http({
       method: 'POST',
       url: url,
       headers: {'Access-Control-Allow-Origin': '*'},
       data: _data}).then();
  </code></pre>
  
  <p>but it didn't work either. Please let me know if I am missing something. </p>
  
  <p>Thankx</p>