.net core api 静态文件允许跨域

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(env.ContentRootPath + "/assets"),
                OnPrepareResponse = (c) =>
                {
                    c.Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                },
                RequestPath = "/services/v1/assets"
            });
    }

修改返回头部

c.Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

  

posted @ 2022-05-24 17:13  86727515  阅读(198)  评论(0编辑  收藏  举报