【问题标题】:Why is my controller action being called twice?为什么我的控制器动作被调用了两次?
【发布时间】:2016-07-19 22:54:37
【问题描述】:

我有一个返回 PDF 报告/文件的控制器操作(请参见下文)。我正在使用下面的本地 URL 来调用此特定操作。

http://localhost:35201/Reports/TimeCards/f6c17d29-93fa-4a34-9aa5-d95371253d0d

由于某种原因,该操作被调用了两次。服务器上的资源消耗加倍。在客户端,我看到对 chrome 开发人员工具的两个调用。第一次调用以 200 结束,然后立即发出另一个调用并将其标记为已取消,但 PDF 呈现仍会在第二次调用时在服务器上进行。

我想消除第二次调用以节省资源。有没有人经历过类似的事情?我将不胜感激。

public ActionResult TimeCards(Guid id)
{
//id = BatchId

//init variables
string sigFile = string.Empty;
Guid company = GetCompanyId();

//get PayrollBatch record
PayrollBatch batch = this.payrollService.GetBatch(id);

//render report this returns a pdf file
byte[] renderedBytes = this.reportService.ProcessTimeCardReport(id, company, this);

return File(renderedBytes, "application/pdf");
}

【问题讨论】:

  • 所以你的客户端代码调用了两次?你愿意分享一下吗?
  • 我删除了所有客户端代码来测试这个问题。这些是我正在采取的步骤。 1. 在本地以调试模式运行应用程序。 2. 验证并关闭所有选项卡。 3.打开一个新窗口(显示开发者工具的chrome)以确保没有任何JS可能导致第二次调用。 4. 粘贴​​下面的 URL。请注意,我没有返回任何 HTML 或视图。我将 PDF 文件本身直接返回到浏览器。

标签: asp.net asp.net-mvc


【解决方案1】:

这看起来像是 Chrome 中的一个问题:https://bugs.chromium.org/p/chromium/issues/detail?id=587709

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 2011-09-04
    相关资源
    最近更新 更多