Angular 如何解决';内容配置';标题在浏览器中显示空值
在我的angular应用程序中,我使用从WebAPI核心返回的excel文件。我还在API方法的content disposition头中设置了一个文件名。但我无法从API获取内容处置头。如何解决这个问题 Api方法代码为:Angular 如何解决';内容配置';标题在浏览器中显示空值,angular,asp.net-core,content-disposition,Angular,Asp.net Core,Content Disposition,在我的angular应用程序中,我使用从WebAPI核心返回的excel文件。我还在API方法的content disposition头中设置了一个文件名。但我无法从API获取内容处置头。如何解决这个问题 Api方法代码为: [HttpGet("ExportToExcelAsync")] public async Task<IActionResult> ExportToExcelAsync(int id, int rId) {
[HttpGet("ExportToExcelAsync")]
public async Task<IActionResult> ExportToExcelAsync(int id, int rId)
{
var Details = await _Service.GetDetails(id, rId);
var excelFile = exportToExcel.ExportExcel(Details ,
templatePath).Result;
var content = excelFile.ToArray();
var actualFile = Details.DocumentName;
Response.Headers.Add("x-file-name","" + actualFile + ".xlsx");
Response.Headers.Add("Content-Disposition", "" + actualFile + ".xlsx");
return File(
content,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"" + actualFile + ".xlsx");
}
}));
}在ASP.NET Core WebAPI后端应用程序中启用CORS时,您可以尝试启用CORS,如下所示
.WithExposedHeaders("x-file-name", "Content-Disposition")
可能不相关:您为内容处置设置的值无效。非常感谢。问题解决了,我从内容配置中获得了文件名。
.WithExposedHeaders("x-file-name", "Content-Disposition")