我构建了一个ASP.NET Web服务,并在该服务中启用了CORS。此服务用于提供报表模板资源(html, image, css, font)
。web客户端根据下载的模板加载模板并显示报表。
因此,给定服务enpoint:http://templates.domain.com
,并且我尝试从web应用程序(http://client.domain.com
)访问服务(REST, Image, Font)
,那么web客户端应用程序将加载:
http://templates.domain.com/templates/:templateName
http://templates.domain.com/templates/:templateName/css/style.css
http://templates.domain.com/templates/:templateName/image/header.jpg
http://templates.domain.com/templates/:templateName/font/test.ttf
在上面,REST、CSS和来自服务的图像运行良好,但是字体被阻塞/失败。
来自原点的字体“http://localhost:49350”已被跨源资源共享策略阻止加载:请求的资源上没有“访问控制-允许-原产地”标题。原点‘空’
到目前为止,我已经尝试了下面的解决方案,但是字体仍然被阻塞。
Microsoft.Owin.Cors
:
app.UseCors(CorsOptions.AllowAll);
Microsoft.AspNet.WebApi.Cors
:
var cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors);
发布于 2015-09-11 09:58:22
您是使用OWIN还是WebAPI?
对于AspNet WebAPI,以下内容允许所有内容通过:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
重要的是要指出,允许"*“是潜在的安全漏洞,因为您是说任何人都可以调用这些方法。
https://stackoverflow.com/questions/32519603
复制相似问题