The 'Access-Control-Allow-Origin' header contains multiple values

0

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);
    
asked by José MN 23.12.2016 в 18:29
source

1 answer

0

Try removing this part of WebApiConfig.cs :

EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);

And define the following in the controller class:

[EnableCors("*", "*", "*")]
public class MiClaseController : ApiController
...
    
answered by 23.12.2016 в 18:41