我正在使用 Rotativa 生成我的 Razor View 的 pdf。它在我的本地机器上运行良好,但是当我将网站发布到网络主机并尝试生成 pdf 时,出现以下错误:
控制器动作方法
//Generate and output the View pdf file
public ActionResult PDFCatalogue(int id)
{
var productList = db.ProductImages.Include("Products")
.Select(m => new ProductDisplayViewModel
{
ProductId = m.Id,
Name = m.Products.Name,
ImageUrl = m.URL,
Thumbnail = m.URL.Replace(".jpg", "-thumb.jpg"),
CategoryId = m.Products.CategoryId,
CategoryName = m.Products.Category.CategoryName,
Sizes=m.Products.Sizes
}).Where(i => i.CategoryId == id).OrderByDescending(m => m.ProductId).ToList();
TempData["CategoryName"] = db.Category.Where(m => m.Id == id).Select(k => k.CategoryName).SingleOrDefault();
if (productList == null)
{
return HttpNotFound();
}
return View("~/Views/Catalogue/PDFCatalogue.cshtml", productList);
//return new RazorPDF.PdfResult(productList, "~/Views/Catalogue/PDFCatalogue.cshtml");
//return new MvcRazorToPdf.PdfActionResult("~/Views/Catalogue/PDFCatalogue.cshtml", productList);
}
public ActionResult GeneratePDF(int id=0)
{
return new Rotativa.ActionAsPdf("PDFCatalogue", new { id = id });
}
“/”应用程序中的服务器错误。 Unhandled Execution Error 描述:在当前web请求的执行过程中发生了一个未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
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) +975
Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches) +50
Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context) +96
Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +250
Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +66
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +75
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651796
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
PS:RotativaRotativa
在应用程序的根目录中创建一个目录,wkhtmltopdf.exe
我也将Rotativa
目录的权限设置为对应用程序池用户的完全控制