【问题标题】:IIS not returns PDF only Excel in Web ApiIIS 在 Web Api 中不仅返回 PDF Excel
【发布时间】:2018-07-03 23:35:01
【问题描述】:

我使用 Vue 在 .Net Core 2.1 中构建了一个应用程序,在调试模式下一切正常,甚至,我使用 Microsoft Printer PrintDocument 打印一张票。但是当我发布 web api 和 Net Core 2.1 在 iis 中发布时,Web Api 不返回 PDF,只得到一个 EXCEL 文档,Excel 可以正常工作,但 PDF 不行。

我使用 ITextSharp 生成 PDF。

我这样返回 PDF:

          return new HttpResponseMessage
      {
        Content = new StreamContent(stream)
        {
          Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/pdf"),
            ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "myfile.pdf"
            }
        }
        },
        StatusCode = HttpStatusCode.OK
      };
    }

如何使用 IIS 返回 pdf?

【问题讨论】:

  • 当您尝试返回 pdf 时究竟会发生什么?你有什么错误吗?
  • @ChetanRanpariya 我没有收到错误,只有我得到响应 = OK,但没有 pdf

标签: c# pdf iis itext


【解决方案1】:

如果返回OK,则检查下载的文件是否存在于下载浏览器文件夹或使用其他浏览器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-20
    • 2015-08-22
    • 2016-12-19
    • 2023-03-26
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2016-12-17
    相关资源
    最近更新 更多