RotativaPDF css 在服务器上不起作用

Ali*_*oto 4 asp.net asp.net-mvc rotativa

我有一份报告,它通常在带有 css 的本地主机中工作。但是当我放在服务器上时,不会使用捆绑包加载CSS。

代码 :

public ActionResult ParseSendPDF()
{
    var result = Session["Search"] as List<Order>;
    ViewAsPdf pdf = new ViewAsPdf("SendPDF", result);
    pdf.PageOrientation = Rotativa.Options.Orientation.Landscape;
    pdf.PageSize = Rotativa.Options.Size.A4;
    pdf.CustomSwitches = "--background";
    foreach (var results in result)
    {
        foreach (var detail in results.OrderDetails)
        {
             var description = detail.Description;
             if (description.Length > 84)
             {
                 SetBreakLine(ref description);
                 detail.Description = description;
             }
        }
    }
    return pdf;
}
Run Code Online (Sandbox Code Playgroud)

看法 :

@model List<Models.Order>
@{
    Layout = null;
 }

 <!DOCTYPE html>
 <html>
 <head>
    <meta name="viewport" content="width=device-width" />
    <title>Reports</title>
    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/trip")
    @Styles.Render("~/Content/datetimepicker")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/ajax")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/datetimepicker") 
    <style type="text/css">
        table { page-break-inside:auto }
        tr    { page-break-inside:avoid; page-break-after:auto }
        thead { display:table-header-group }
        tfoot { display:table-footer-group }
    </style>
</head>
<body>
    <img style="margin-top: -7px;" class="img-responsive"    src="~/Content/Images//logo.png" />
    <h1 class="text-center">Reports</h1>
    @Html.Partial("_Index", Model)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在本地主机中工作但在服务器中,我的 CSS 和徽标不起作用。

Rac*_*der 5

我花了几周的时间来解决这个问题,并且尝试了 Stack Overflow 提供的所有建议:

  • 为在 IIS 服务器上创建的用户提供带有用户名和密码的自定义交换机
  • 为在 Active Directory 上创建的用户提供带有用户名和密码的自定义交换机(因为我的应用程序是通过 Active Directory 进行身份验证的)
  • 调整了所有用户对 IIS 上 wkhtmltopdf.exe 的权限
  • 将 .min 和普通 css 文件添加到捆绑列表中
  • 调整 CSS 文件的权限

最后,我最终删除了捆绑包引用,并在布局页面标题中明确说明了我的 CSS 文件,并且它起作用了。

<link rel="stylesheet" type="text/css" href="~/Content/bootstrap.min.css"/>
Run Code Online (Sandbox Code Playgroud)