如何在 Windows 10 的 IIS 管理器上启用 CORS?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44802613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable CORS on IIS Manager of Windows 10?
提问by CrazySynthax
I've created an HTTPS server using IIS Manager (Windows 10). Now, I want this server to support CORS requests.
我已经使用 IIS 管理器(Windows 10)创建了一个 HTTPS 服务器。现在,我希望此服务器支持 CORS 请求。
I've read some information. For example, thislink says that I have to create a file web.config in the directory. Unfortunately, it didn't work out. Thislink says that I should edit some config files, but I don't find them on my machine.
我读了一些资料。例如, 这个链接说我必须在目录中创建一个文件 web.config。不幸的是,它没有成功。 这个链接说我应该编辑一些配置文件,但我没有在我的机器上找到它们。
回答by KOTIX
I had a similar issue recently. Most tutorial/documentation only suggests adding custom headers in the configuration. But this does not tell IIS to handle the CORS Pre-flight request by itself.
我最近遇到了类似的问题。大多数教程/文档仅建议在配置中添加自定义标头。但这并没有告诉 IIS 自己处理 CORS 预检请求。
To do so, you must install the CORS Modulein IIS and add some configuration in the web.config file, as explained here: IIS CORS module Configuration Reference
为此,您必须在 IIS 中安装CORS 模块并在 web.config 文件中添加一些配置,如下所述:IIS CORS 模块配置参考
I recently used this to Reverse Proxy to a REST API and handling the CORS only in IIS so that I don't have to rebuild my project to change CORS settings.
我最近使用它来将代理反向到 REST API 并仅在 IIS 中处理 CORS,这样我就不必重建我的项目来更改 CORS 设置。