首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在本地工作而不是在IIS 7上工作的Rotativa PDF生成

在本地工作而不是在IIS 7上工作的Rotativa PDF生成
EN

Stack Overflow用户
提问于 2015-06-29 09:36:41
回答 7查看 30.1K关注 0票数 36

我有一个ASP.NET MVC 5应用程序。它有一个简单的表单,当用户提交表单时,表单存储在缓存中,然后调用另一个控制器操作,此操作将作为PDF视图返回模型。

我不需要在本地保存它,只需要在浏览器中显示它,这样用户就可以下载它。

也不需要数据库,这就是为什么我将模型存储在缓存中。

在当地,在Visual 2013上,它工作得很好。但是当我将它发布到IIS 7时,我会得到一个Unhandled Execution Error。下面是我得到的堆栈跟踪:

代码语言:javascript
运行
复制
 Unhandled Execution Error
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception:

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[Exception]
   Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +1364
   Rotativa.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html) +70
   Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) +1986
   Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +380
   Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +69
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248 

我最初使用ActionAsPDF(),但现在也尝试使用return new ViewAsPDF()。两者都提供相同的错误和堆栈跟踪。这一定要用权限来做吗?

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2015-07-08 14:00:12

此错误是Visual 2013文件(MSVCP120.dll)缺少的C++可再发行包。

为解决这一问题:

  1. 打开Visual 2013可下载的C++可再发行包,链接如下:下载Visual 2013的VisualC++可再发行包
  2. 单击“下载”并选择文件(vcredist_x86.exe),即使您正在运行X64位服务器版本。
  3. 安装文件。

有关更多细节,请访问Jalal博客http://jwhijazi.blogspot.com/2015/05/solving-rotativa-unhandled-exception.html

票数 57
EN

Stack Overflow用户

发布于 2016-04-26 23:33:01

正如答案中链接的博客上的注释所提到的,如果您不想/不能轻松地在服务器上安装东西,可以将下面的2个dll文件复制到服务器上的rotativa文件夹中。

msvcr120.dll

msvcp120.dll

如果它在本地工作,那么应该已经有两个dll文件可用了。您需要x86版本,如果您发现与vs 2015一起打包的x64版本,它们将无法工作。我在这里找到了正确的版本:

代码语言:javascript
运行
复制
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC120.CRT

在升级到Rotativa 1.7.3之后,这不再有效。我不得不复制了一些来自visual studio 2017的新dll,这次我在这里找到了它们:

代码语言:javascript
运行
复制
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT

我不得不复制

msvcp140.dll

vcruntime140.dll

票数 18
EN

Stack Overflow用户

发布于 2017-07-12 12:35:42

这个被接受的答案几乎对我有用。我错过了C++可再发行版的更新版本,所以安装旧版本没有帮助。

找出您缺少的最简单的方法是手动运行wkhtmltopdf.exe。它要么为您提供控制台输出(如果工作),要么给您一个关于缺少什么的消息框。

我丢失了MSVCP140.dll,它来自VS 2015 redist,可在这里获得:https://www.microsoft.com/en-gb/download/details.aspx?id=48145

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31112349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档