【问题标题】:Rotativa had problems with css style on serverRotativa 在服务器上的 css 样式存在问题
【发布时间】:2014-12-08 22:53:32
【问题描述】:

我在我的 ASP.net MVC 项目中使用Rotativa。我使用 ViewAsPDF 作为返回类型。问题是在本地环境中一切运行顺利,css 样式正确应用于 PDF,但是当我在 prod 服务器上部署我的应用程序并尝试获取 PDF 文件时,服务器仅在不应用 CSS 样式的情况下在 5 分钟后返回它.如果我将风格直接赋予属性<td style="..."> 有用。我在哪里可以找到问题,以及如何解决?

谢谢!

更新: 如果我删除指向 CSS 样式表的链接,它的工作速度会更快:

更新: 如果我在我的任何网站页面上手动运行 wkhtmltopdf.exe,我会得到:

%computername% | D:\Projects\myapp\trunk\WebSite\Rotativa>wkhtmltopdf http://myappp.com pdf.pfd
Loading pages (1/6)
Error: Failed loading page http://finishgenius.tizbi.com (sometimes it will work just to ignore this error with --load-error-handling ignore)

更新: 如果我将 ViewAsPdf 方法更改为 ActionAsPDF 我收到错误:

Server Error in '/' Application.

Error: Failed loading page http://myapp.com/FinishingSchedules/PrintScheduleDetails/2?Name=Schedule No.2&CostPerSquareFootMaterial=0.06&CostPerSquareFootLabor=54&DirectCostOfMaterialsAndLabor=108.12&TotalPriceWithMarkUp=118.93&TotalJobSize=2&ProductionTime=36&MaterialsQuantities=System.Collections.Generic.List`1[WebSite.ViewModels.FinishingSchedules.MaterialsQuantities] (sometimes it will work just to ignore this error with --load-error-handling ignore)

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: Error: Failed loading page http://myapp.com/FinishingSchedules/PrintScheduleDetails/2?Name=Schedule No.2&CostPerSquareFootMaterial=0.06&CostPerSquareFootLabor=54&DirectCostOfMaterialsAndLabor=108.12&TotalPriceWithMarkUp=118.93&TotalJobSize=2&ProductionTime=36&MaterialsQuantities=System.Collections.Generic.List`1[WebSite.ViewModels.FinishingSchedules.MaterialsQuantities] (sometimes it will work just to ignore this error with --load-error-handling ignore)


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: Error: Failed loading page http://myapp.com/FinishingSchedules/PrintScheduleDetails/2?Name=Schedule No.2&CostPerSquareFootMaterial=0.06&CostPerSquareFootLabor=54&DirectCostOfMaterialsAndLabor=108.12&TotalPriceWithMarkUp=118.93&TotalJobSize=2&ProductionTime=36&MaterialsQuantities=System.Collections.Generic.List`1[WebSite.ViewModels.FinishingSchedules.MaterialsQuantities] (sometimes it will work just to ignore this error with --load-error-handling ignore)
]
   Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +570
   Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context) +26
   Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +128
   Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   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() +9633216
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

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

【问题讨论】:

  • 看起来库在某些时候调用了 .exe。网站在什么权限级别/用户下运行?
  • 是的,它调用 wkhtmltopdf.exe。经过身份验证的用户、系统、管理员拥有完全控制权。 .Net 信任级别为完整。在这种情况下应该是什么权限级别/用户
  • 这似乎是 Webkit PDF 库 (wkhtmltopdf) 的问题。插件作者推荐了一个预发布分支;在 Package Manager 控制台中输入 Install-Package Rotativa -Pre(确保在控制台中选择了 web 项目),看看是否有效。
  • 完全信任是您所能达到的最高水平。中等信任可能会阻止插件调用的 Process.Start,因此值得将其排除。不过,可能不应该以管理员身份运行。我认为 NETWORK_SERVICE 用户(或现在的任何等效用户)具有运行 IIS 所需的权限。不过,这是 ServerFault 的问题。
  • 将 Rotativa 版本更改为 pre,还添加了 IIS_USER、IUSER,一个具有完全控制权的 NETWORK SERVICE 用户 - 没有帮助

标签: html css asp.net-mvc wkhtmltopdf rotativa


【解决方案1】:

终于找到了我问题的根源。我试图从服务器的浏览器访问我的网站,我发现服务器看不到自己。我用正确的 IP 地址更新了 hosts.txt 文件,这解决了我的问题。希望这会对某人有所帮助!谢谢!

【讨论】:

    【解决方案2】:

    当您的网站使用 Windows 身份验证时,可能会发生这种情况。

    您需要在 web.config 中授予对 CSS 文件的访问权限,如下所示:

    <location path="content">
        <system.web>
          <authorization>
            <allow users="*" />
          </authorization>
        </system.web>
      </location>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-23
      • 2011-09-14
      • 2017-03-04
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      相关资源
      最近更新 更多