添加后缀 fd=1
http://localhost:5775/img.png?fi=1
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(path),
RequestPath = rPath.ToString().Trim('~'),
OnPrepareResponse = (c) =>
{
c.Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
c.Context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS, TRACE, HEAD, PATCH");
//c.Context.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
c.Context.Response.Headers.Add("Access-Control-Allow-Headers", "*");
//静态文件下载 fd=1
var request = c.Context.Request;
var response = c.Context.Response;
if (request.Query.ContainsKey("fd"))
{
response.Headers.Add("Content-Disposition", "attachment; filename=" + Path.GetFileName(request.Path));
}
}
}).
文档更新时间: 2023-04-10 22:23 作者:admin