问题描述
我正在使用Rotativa将视图转换为PDF.它可以在我的本地计算机上运行,但是在IIS服务器上发布时会出现如下错误:
I am using Rotativa for convert the view to PDF. It works on my local but when published on IIS server it gives error as below:
源错误:
堆栈跟踪:
[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
projectName.Models.ViewAsPdf2.GetByte(ControllerContext context) in C:\Users\username\Documents\Visual Studio 2015\Projects\projectName\Models\ModelClass.cs:91
projectName.Controllers.<ModelClass>d__1.MoveNext() in C:\Users\username\Documents\Visual Studio 2015\Projects\projectName\Controllers\FormsController.cs:40
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +143
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +23
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +112
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +452
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +32
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +231
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
不确定服务器为什么显示控制器上下文的本地路径.我正在使用默认路由.我有什么需要修改的东西吗?
Not sure why the server is showing my local path for the controller context. I am using the default routing. Is there anything specifically that I need to modify?
这是我用来传递控制器的代码段:
Here is the code snippet that I use to pass the controller:
ControllerContext context = new ControllerContext(Request.RequestContext, this);
var pdf = new ViewAsPdf2("ModelClass", model);
byte[] pdfByteArray = pdf.GetByte(context);
这是GetByte的代码
Here is the code for GetByte
public class ViewAsPdf2: PartialViewAsPdf
{
public ViewAsPdf2(string viewName, object model) : base (viewName, model) {
}
public byte[] GetByte(ControllerContext context)
{
base.PrepareResponse(context.HttpContext.Response);
base.ExecuteResult(context);
return base.CallTheDriver(context);
}
}
推荐答案
在进行了一些研究之后,我发现为我解决了Rotativa无法解决服务器问题的问题:
After doing some research here is what I found that resolved the Rotativa not working on server issue for me:
Rotativa用于生成PDF的wkhtmltopdk.exe使用以下DLL
The wkhtmltopdk.exe used by Rotativa to generate PDFs uses the following DLLs
MSVCP120.dll MSVCR120.dll
这两个dll是两个不同的可安装软件包的一部分:
These two dlls are part of two different install able packages:
- MSVCP120.dll 附带了Visual C ++可再发行组件包,用于Visual Studio 2010 64位软件包
- MSVCP120.dll comes with Visual C++ Redistributable Packages forVisual Studio 2010 64 bit package
和
-
MSVCR120.dll 附带了Visual C ++可再发行组件包,用于Visual Studio 2013 32位程序包
MSVCR120.dll comes with Visual C++ Redistributable Packages forVisual Studio 2013 32-bit package
如何检查Rotativa使用的dll是否在正确的位置?好像rotativa使用来自的dllC:\ Windows \ SysWOW64
How to check if the dlls used by rotativa are in right place or not?It looks like rotativa uses dlls fromC:\Windows\SysWOW64
确保以上文件夹中存在MSVCP120.dll和MSVCR120.dll.我之前是指C:\ Windows \ System32文件夹,但是那里的dll对我没有任何帮助,进一步加剧了混乱.
Make sure MSVCP120.dll and MSVCR120.dll are present in the above folder. I was referring to C:\Windows\System32 folder earlier but having the dlls there did not do any good to me and added further to the confusion.
希望这会有所帮助.
这篇关于在IIS上发布时,带有Rotativa的MVC5应用程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!