【问题标题】:Generate and download excel file from .Net core Web Api returns 500 error从 .Net core Web Api 生成和下载 excel 文件返回 500 错误
【发布时间】:2019-07-26 14:14:23
【问题描述】:

我正在尝试从 .Net Core Web Api 生成和下载一个 excel 文件。此 Web api 托管在 azure app services 中。使用 EpPlus 包生成的 Excel 文件。该文件通过传递日期范围和一些其他参数生成。文件的大小取决于日期范围。当我为日期范围文件下载提供 1 天没有问题时,因为文件的大小很小。当我给大日期范围服务器返回“500 - 请求超时”。

我尝试在 azure app service 上进行远程调试,只需要 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 应用服务中的 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();

我在这里做错了什么?非常感谢您的反馈。提前致谢

【问题讨论】:

    标签: asp.net-core iis .net-core azure-web-app-service asp.net-core-webapi


    【解决方案1】:

    根据你的描述,我建议你可以尝试开启失败请求追踪,看看是哪个模块处理了这么久,你可以为进程生成一个完整的转储,并使用调试对话框分析来分析转储文件以找出原因。

    关于如何在 Azure 中使用 FRT,可以参考这个article

    关于如何抓包,可以参考article

    关于如何使用debugdialog分析来分析dump文件,可以参考这个article

    【讨论】:

      猜你喜欢
      • 2018-10-04
      • 2020-09-07
      • 1970-01-01
      • 2021-03-25
      • 2021-01-20
      • 2016-12-17
      • 2020-04-10
      • 2020-08-30
      • 2020-10-10
      相关资源
      最近更新 更多