asp.net-core - 从 .Net core Web Api 生成和下载 excel 文件返回 500 错误
问题描述
我正在尝试从 .Net Core Web Api 生成和下载一个 excel 文件。此 Web api 托管在 azure app services 中。使用 EpPlus 包生成的 Excel 文件。该文件通过传递日期范围和一些其他参数生成。文件的大小取决于日期范围。当我为日期范围文件下载提供 1 天没有问题时,因为文件的大小很小。当我给大日期范围服务器返回“500 - 请求超时”。
我尝试在 azure app 服务上进行远程调试,只需要 2 分钟即可完成请求并返回响应。但它不会返回到网络浏览器
这是我的 web api 获取方法
[HttpGet]
public FileResult GetReport(String StartDate, String EndDate, bool SIH, bool FinalOrder, bool Allocations, Boolean GRN, bool ActualSale, bool Buffers, bool FillRate, bool Forecast)
{
//Generating exel file in to a byte[] using EpPlus package here
var memoryStream = new MemoryStream();
excel.SaveAs(memoryStream);
byte[] byteArray = memoryStream.ToArray();
memoryStream.Close();
const string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Response.ContentType = contentType;
HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
var fileContentResult = new FileContentResult(stream, contentType)
{
FileDownloadName = "Infor-Report.xlsx"
};
return fileContentResult;
}
这是我在 azure app 服务中的 web.config 文件
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\JMSL.OMS.BackEnd.API.dll" requestTimeout="00:20:00" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false">
<environmentVariables />
</aspNetCore>
还有我的program.cs
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
})
.Build();
我在这里做错了什么?非常感谢您的反馈。提前致谢
解决方案
推荐阅读
- javascript - 悬停时打开菜单而不是使用 jQuery 单击
- list - 如何计算飞镖地图列表中元素的出现次数?
- css - Angular 材质 mat-form-field 有效颜色
- react-native - 如何在 React-Navigation 5 中定义不同的导航流组
- unit-testing - 为 amazonSNS.publish() 编写测试用例时出错
- vba - 更改纵横比而不失真且边缘没有黑条(取决于播放的屏幕尺寸)
- c# - AcquireTokenAsync 在 1 或 2 小时后到期
- javascript - 为什么子元素没有占据其父元素的 100% 高度?
- microsoft-graph-api - Microsoft 团队:filesFolder 正在为新创建的团队/频道返回 404
- julia - MethodError:用户定义的函数中没有方法匹配