Cors doesnt solve cross origin requests

I have trying to build an angular app using ASP.NET MVC Web API.

When i make a $resource request to my web server (localhost) I get

XMLHttpRequest cannot load http://localhost:59636/api/studios. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:44060' is therefore not allowed access. The response had HTTP status code 401.

I read that installing Cors would solve this. But it doesnt. I have tried both enabling cors

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

as well as using an the attribute

[EnableCorsAttribute("*", "*", "*")]

It is working on IE

也许这有助于?我打电话给默认的api /值


In your WebApiConfig.cs file you should have:

        config.EnableCors();

In your ApplicationOAuthProvider.cs, in GrantResourceOwnerCredentials():

context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin",
                new[] { "http://localhost:44060" });

And over the controller:

[EnableCorsAttribute("http://localhost:44060", "*", "*")]
链接地址: http://www.djcxy.com/p/62774.html

上一篇: 如何在scala中做递归循环

下一篇: Cors不能解决交叉来源请求