I have a simple ASP.NET Web API application with individual accounts for authentication.
I enabled CORS in it: installed package and added:
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
to the file WebApiConfig.
Now, I want to make requests from a simple web page using jQuery. I have this code now:
var loginData = {
grant_type: "password",
username: "foo",
password: "Something_1562"
};
$.ajax({
type: 'POST',
url: "https://localhost:44351/Token",
data: loginData
}).done(function (data) {
alert(data.userName);
alert(data.access_token);
}).fail(function (data) {
alert('Request Status: ' + req.status + ' Status Text: ' + req.statusText + ' ' + req.responseText);
});
And I get this:
XMLHttpRequest cannot load https://localhost:44351/Token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
EDIT:
Some extra information: - I have https/ssl enable on the web api - The API is running on ISS Express