[英]Is there a way to enable CORS on an Azure Virtual Machine?
Is there a way to enable CORS on an Azure Virtual Machine ?有没有办法在 Azure 虚拟机上启用 CORS? I am running a flask at localhost:5001 and angular app at localhost:4200 In my local environment, it woks perfectly.我在 localhost:5001 上运行一个烧瓶,在 localhost:4200 上运行 angular 应用程序在我的本地环境中,它完美地工作。 However, in the virtual machine instance on azure it doesn't work because I can't setup my CORS.但是,在 azure 上的虚拟机实例中它不起作用,因为我无法设置我的 CORS。
To enable CORS in azure , we need to configure a policy in APIs by following below steps.要在 azure 中启用 CORS,我们需要按照以下步骤在 API 中配置策略。
1. Add the APIs required in the azure portal . 1. 添加azure 门户中所需的API 。
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" /> <add name="Access-Control-Allow-Headers" value="Content-Type" /> </customHeaders> </httpProtocol> </system.webServer>
To see how to go to web.config file you may refer this Link to Configure CORS in azure要查看如何转到 web.config 文件,您可以参考此链接以在 azure 中配置 CORS
2. Go to APIs >> click on all operations >> Add policy 2. 前往 APIs >> 单击所有操作 >> 添加策略
- There you can see cors.Click on it. - 在那里你可以看到 cors。点击它。
- Then click on save - 然后点击保存
- You will need to navigate to the inbound policy and check if you have this element added. - 您需要导航到入站策略并检查是否添加了此元素。
(Or) (要么)
You may refer this Document for more information .您可以参考本文档了解更多信息。
You may Enable the Access-Control-Allow-Credentials header.您可以启用 Access-Control-Allow-Credentials 标头。 This is necessary whenever you need to send cookies or a token as part of calling your API >> Reference每当您需要发送 cookie 或令牌作为调用 API 的一部分时,这是必要的 >> 参考
(OR) (要么)
In AZURE CLI:在 AZURE CLI 中:
webapp cors add --resource-group myResourceGroup --name <app-name> --allowed-origins 'http://localhost:5000'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.