I am working with ASP.NET WEB Api, and I am using the Token generation, in Internet Explorer I generate the Token chain:
but using any other browser shows me the following error ...
AJAX Code:
function ObtenerToken(user, password) {
var data = { username: user, password: password, grant_type: "password" }
$.ajax({
url: 'http://localhost:50196/Token',
method: "post",
data: data,
contentType: "application/json",
error: function (e) {
alert('Hubo un error al intentar autenticar al usuario.');
console.log(e);
},
success: function (response) {
var token = response.access_token;
alert(token);
}
});
}
I have added the following to the Startup.Auth.cs file:
app.UseCors(CorsOptions.AllowAll);
In WebApiCofig.cs:
EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);