1,友虹查看ofd跨域问题
一,环境
使用友虹标准版网页调用 .net core 中wwwroot中静态文件(ofd格式文件),发生错误。
二,错误信息
Access to XMLHttpRequest at 'http://api.test.com/xxx' from origin 'http://www.test.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
三,解决
通过错误信息,可以看出,在请求时缺少Access Control Allow Origin
在.net core 中Startup.cs的Configure方法加入
app.UseStaticFiles(new StaticFileOptions{
ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string ,string >{
{".ofd","application/vnd.openxmlformats-officedocument.wordprocessingml.document"}
}),
OnPrepareRespose = (c) => {
c.Context.Response.Headers.Add("Access-Control-Allow-Origin","*");
}
})
本文来自博客园,作者:zwbsoft,转载请注明原文链接:https://www.cnblogs.com/zwbsoft/p/15964014.html
电话微信:13514280351