title: Asp.net WebAPI enable Cors to specific SSL/https origin
body: <p>Below is part of my web api project.</p>
  
  <pre><code>public class TriviaController : ApiController
  {        
      public HttpResponseMessage Get()
      {
          QuestionAnswer _QuestionAnswer = new QuestionAnswer();
          TriviaQuestion _TriviaQuestion = _QuestionAnswer.GetQuestion("test@yahoo.com");
          return Request.CreateResponse(HttpStatusCode.OK, _TriviaQuestion);
      }    
  }
  
  public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          EnableCrossSiteRequests(config);
          AddRoutes(config);
      }
  
      private static void AddRoutes(HttpConfiguration config)
      {
          config.Routes.MapHttpRoute(
              name: "Default",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
      }
  
      private static void EnableCrossSiteRequests(HttpConfiguration config)
      {
          var cors = new EnableCorsAttribute(
              origins: "*",
              headers: "*",
              methods: "*");
          config.EnableCors(cors);
      }
  }
  </code></pre>
  
  <p>My client application receive json data which returned by contoller.
  Everything working correct until I modify to specific origins like below.</p>
  
  <pre><code>var cors = new EnableCorsAttribute(
              origins: "https://jsfiddle.net/", //"https://localhost:44304/",
              headers: "*",
              methods: "*");
  </code></pre>
  
  <p>After that, my client application receive only null value and error message saying Status Code 0.<br>
  According to <a href="https://stackoverflow.com/a/2016085/900284">this reference link</a>, I know that it is because of CORS.<br></p>
  
  <p>Below is my client code. It is so simple.</p>
  
  <pre><code>alert("*");
  $.getJSON("https://localhost:44300/api/trivia", function(data) {
    alert(JSON.stringify(data));
  })
  .done(function() { alert('getJSON request succeeded!'); })
  .fail(function(jqXHR, textStatus, errorThrown) { 
  alert('getJSON request failed! ' + textStatus + ' :: ' + jqXHR + ' :: ' + errorThrown); 
  
  $.each(jqXHR, function(k, v) {
      //display the key and value pair
      alert(k + ' is ' + v);
  });
  
  })
  .always(function() { alert('getJSON request ended!'); });
  </code></pre>
  
  <p>To see on jsFiddle, click <a href="https://jsfiddle.net/0bz4je9o/4/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>So my question is, <br>
  Is it possible to set allow origin using SSL? If so what am I doning wrong?</p>