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","*");
       }
  })
 
posted @ 2022-03-04 13:56  zwbsoft  阅读(157)  评论(0)    收藏  举报