Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果这是一个动态响应,我会这样做,Response.Headers.Add("Access-Control-Allow-Origin", "*");但我有一个静态文件,我想允许跨域访问。
Response.Headers.Add("Access-Control-Allow-Origin", "*");
有没有办法仅使用 web.config 将此标头分配给特定文件?说它只是 example.com/flat.json
我想我可以将文件路由到动态页面,但这有点傻。
这应该工作
<location path="Sample.txt"> <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> </system.webServer> </location>