Angular & # 8594; Web Api 2: None Access-Control-Allow-Origin '

I'm basically trying to access my web api which is uploaded to Azure.

I added my CORS attribute to the WebApiConfig class:

public static void Register(HttpConfiguration config) { var cors = new EnableCorsAttribute("http://localhost:51407", "*", "*"); config.EnableCors(cors); 

However, whenever I send an Ajax request (using angularJS), which rightfully contains

 Origin: http://localhost:51407 

I get an error message:

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:51407' is therefore not allowed access. 

What could be the problem?

+6
source share
2 answers

For a .NET server, this can be configured in web.config, as shown below.

  <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="your_clientWebUrl" /> </customHeaders> </httpProtocol> </system.webServer> 
+1
source

I also work with webapi2 and the AngluarJS client (different servers) on Azure WebSites.

please check my answer: fooobar.com/questions/94667 / ...

If you cannot solve the problem, check the other answers of the above link.

0
source

Source: https://habr.com/ru/post/976997/


All Articles