我需要打开从另一个网站(AngularJS)调用的单个Web Api方法,我无法使其工作。
我添加了对Microsoft.Owin.Cors
和System.Web.Http.Cors
将此行添加到我的OWIN Startup类的Configuration
方法中:
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
将config.EnableCors();
添加到ConfigureWebApi
方法
已添加
[EnableCors(origins: "*", headers: "*", methods: "*")]
在我的Web Api控制器方法之上。
我还是
XMLHttpRequest cannot load {myUrl}. Response to preflight request doesn't
pass access control check: No 'Access-Control-Allow-Origin' header is present
on the requested resource. Origin 'http://localhost' is therefore not
allowed access. The response had HTTP status code 401.
我尝试了上述不同的组合而没有运气。我还看到了其他回复,其中包括向web.config
和Global.asax
添加代码,但我自己托管了OWIN并且没有任何这些回复。
我怎样才能让它发挥作用?