【问题标题】:Rotativa.Netcore works locally but not after deploymentRotativa.Netcore 在本地工作,但在部署后不工作
【发布时间】:2018-06-27 09:45:21
【问题描述】:

我在 ASP.NET Core 2.1.1 项目中使用最新的 Rotativa.NetCore 程序集。 NuGet (https://www.nuget.org/packages/Rotativa.AspNetCore v. 1.0.6) 不适用于部署 (win2016),但可以在本地 (win10) 运行。

部署的 IIS 给出 404,错误日志(stdout)显示如下:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.Exception
   at Rotativa.AspNetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe)
   at Rotativa.AspNetCore.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html)
   at Rotativa.AspNetCore.ViewAsPdf.CallTheDriver(ActionContext context)
   at Rotativa.AspNetCore.AsResultBase.BuildFile(ActionContext context)
   at Rotativa.AspNetCore.AsResultBase.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

这里是“我的项目”源代码

public IActionResult DownloadCertificate(int id)
{
    var model = getData(id);
    return new ViewAsPdf("PdfCertificate", model)
    {
        WkhtmlPath = "", // set the path to the Rotativa .exe files. works locally but not on deployment. 
        FileName = "Cert.pdf"
    };
}

我尝试将WkhtmlPath 更改为"..\\Rotativa\\",但没有成功。

疑难解答我发现了这个:https://stackoverflow.com/a/48166956/560784 - 显然 Rotativa 是针对 .NET Core 1.0 编译的:

这里有将 Rotativa.NetCore 从 .Net Core 1 更新到 .Net Core 2.0 的代码:https://github.com/aaxelm/Rotativa.NetCore/pull/1/files?diff=split

因此,我下载了 Rotativa 源并相应地更新到 .NET core 2.0,并引用了新程序集。问题仍然存在。

我也检查了权限。 Rotativa 文件夹赋予 IIS_IUSRS 执行权限(运行 ApplicationPoolIdentity)。

我错过了什么?

我的本​​地文件夹结构:

c:\inetpub\myproject\myproject.dll + web.config 等等。 c:\inetpub\myproject\Rotativa{wkhtmltoimage.exe, wkhtmltopdf.exe, wkhtmltox.dll}

我部署的文件夹结构:

c:\inetpub\sites\myproject\myproject.dll + web.config 等等。 c:\inetpub\sites\myproject\wwwroot\(静态文件) c:\inetpub\sites\myproject\Rotativa{wkhtmltoimage.exe, wkhtmltopdf.exe, wkhtmltox.dll}

【问题讨论】:

    标签: c# asp.net-core rotativa


    【解决方案1】:

    原来我需要的是安装Microsoft Visual C++ Redistributable 2017 (x86) - 在这里下载:https://visualstudio.microsoft.com/vs/older-downloads/https://visualstudio.microsoft.com/downloads/

    1. 我已恢复为官方 nuget(为了便于将来维护)https://www.nuget.org/packages/Rotativa.AspNetCore v. 1.0.6
    2. 我将RotativaConfiguration.Setup(env, "..\\Rotativa\\"); 添加到Startup.cs
    3. 我的最终代码如下所示:

    代码:

    public IActionResult DownloadCertificate(int id)
    {
        var model = getData(id);
        return new ViewAsPdf("PdfCertificate", model)
        {
             FileName = "Cert.pdf"
        };
    }
    

    【讨论】:

    【解决方案2】:

    我在使用 asp netcore3.1 开发的项目中遇到了同样的问题,并在安装“Microsoft Visual C++ Redistributable 2017 (x86)”后解决了。无论您的操作系统是 x64 还是 x86,请确保安装 (x86)!谢谢沙!!

    【讨论】:

      【解决方案3】:

      我只需要在服务器上安装 Microsoft Visual C++ Redistributable 2017 (x86)。以前我尝试过其他解决方案,包括将它们安装在 localhost 中,都不起作用,我几乎放弃了! ?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-22
        • 2020-09-24
        • 2021-06-28
        • 1970-01-01
        相关资源
        最近更新 更多