Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Rotativa action aspdf()非常慢_C#_Pdf_Asp.net Mvc 5_Rotativa - Fatal编程技术网

C# Rotativa action aspdf()非常慢

C# Rotativa action aspdf()非常慢,c#,pdf,asp.net-mvc-5,rotativa,C#,Pdf,Asp.net Mvc 5,Rotativa,从NuGet使用,并使用下面的代码注意到以下问题 ActionAsPdf随机挂起的时间不确定 下面挂起的代码: var pdfResult = new ActionAsPdf("Report", new {id = Request.Params["id"]}) { Cookies = cookieCollection, FormsAuthenticationCookieName = FormsAuthentication.FormsCookieNam

从NuGet使用,并使用下面的代码注意到以下问题

ActionAsPdf随机挂起的时间不确定

下面挂起的代码:

   var pdfResult = new ActionAsPdf("Report", new {id = Request.Params["id"]})
    {
        Cookies = cookieCollection,
        FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName,
        CustomSwitches = "--load-error-handling ignore"
    };
可能有帮助的背景信息:

CustomSwitchs用于忽略使用ActionAsPdf调用wkhtmltopdf.exe的记录问题,但它不会仅在wkhtmltopdf调用中抑制代码中的错误

观察、使用和测试:

它可以工作,但在运行应用程序时(无论是否单步执行代码),从点击pdfResult=new ActionAsPdf到最终进入被调用的“Report”操作之间的时间可以是10秒到大约4分钟。无法识别Visual Studio的输出窗口中实际发生的任何事情,我没有发现任何错误。只是随机缓慢过渡到Reports()操作

我可以通过URL直接运行Reports()操作,它不会像这样慢下来,而且生成PDF的速度非常快。我正在使用ActionAsPdf运行它,以获取二进制文件,保存到文件系统并通过电子邮件发送,这是为这个库指定的方法

该行为同时存在于本地Windows 10开发设备和远程服务器2008R2测试设备上。Net 4.5.1在两个框上,每个框上都有默认IIS

我的问题:


你知道是什么原因导致了这种速度减慢,以及如何补救吗?

我最终使用了UrlAsPdf()而不是ActionAsPdf(),而且效果很好。似乎ActionAsPdf()可能有一些问题,我在GitHub上的Rotative项目中发现了一个bug。ActionAsPdf()仍被标记为beta版,因此希望它在将来的版本中或社区中得到修复。

在我的例子中,我不得不在使用UrlAsPdf()的同时做更多的调整。我已经将问题缩小到我正在添加的cookie集合。所以我试着添加我需要的cookie,问题就解决了。下面是我使用的示例代码

        var report = new UrlAsPdf(url);

        Dictionary<string, string> cookieCollection = new Dictionary<string, string>();
        foreach (var key in Request.Cookies.AllKeys)
        {
           if (Crypto.Hash("_user").Equals(key))
           {
              cookieCollection.Add(key, Request.Cookies.Get(key).Value);
              break;
           }
        }
        report.Cookies = cookieCollection;
        report.FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName;
var报告=新的UrlAsPdf(url);
Dictionary cookieCollection=新建字典();
foreach(请求中的var key.Cookies.allkey)
{
if(加密散列(“_user”).Equals(key))
{
添加(key,Request.Cookies.Get(key.Value));
打破
}
}
report.Cookies=cookieCollection;
report.FormsAuthenticationCookieName=FormsAuthentication.FormsCookieName;

这是否解决了速度问题?我的还是很慢。在我的开发机器上需要几分钟的时间。UrlAsPdf()在我使用过的本地开发、测试、阶段和产品环境中没有任何缓慢的问题,其中ActionAsPdf()在所有环境中都有问题,缓慢的速度似乎是随机的,因为我还没有确定任何条件来可靠地重复它。谢谢你回信!)如果你好奇的话,我最终以另一种方式解决了这个问题:很好地解决了我的问题,我很快就会有兴趣尝试。谢谢我也有一个速度慢的问题,结果是视图中的bootstrap减慢了速度。添加参数“-print media type”解决了这个问题。现在我的观点非常简单,它打印的内容基本相同,我可以看出如果你试图打印丰富的内容,这可能不起作用。