We are getting CORS issue in Azure WebAPP still i have allowed all origin as “*”

ε祈祈猫儿з 提交于 2020-04-30 11:04:33

问题


I am getting CORS issue in PROD environment when i am try to login into the site.when i set origin policy as "*" . still it is giving the same CORS issue.

Access to XMLHttpRequest at 'https://XYZ.azurewebsites.net/api/users/userlogin' from origin 'https://XYZ.azurewebsites.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I also have specified the CORS policy in code as well but Azure Web App CORS policy always have precedence over Code CORS policy.

can anyone please help on this?


回答1:


Removed all code-handling of CORS and simply put the headers in the web.config:

<configuration>
 <system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="https://XYZ.azurewebsites.net/api/users/userlogin" />
      <add name="Access-Control-Allow-Methods" value="*" />
      <add name="Access-Control-Allow-Headers" value="accept, content-type, x-my-custom-header" />
      <add name="Access-Control-Allow-Credentials" value="true" />
    </customHeaders>
  </httpProtocol>

Note: Don't try to use App Service CORS and Web API CORS code together. When used together, App Service CORS takes precedence and Web API CORS code has no effect. Refer to this article.



来源:https://stackoverflow.com/questions/55701444/we-are-getting-cors-issue-in-azure-webapp-still-i-have-allowed-all-origin-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!