我正在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)
这是“ myproject”来源
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}
答案 0 :(得分:1)
事实证明,我需要安装Microsoft Visual C++ Redistributable 2017 (x86)
-在此处下载:https://visualstudio.microsoft.com/downloads/
RotativaConfiguration.Setup(env, "..\\Rotativa\\");
添加到了Startup.cs
代码:
public IActionResult DownloadCertificate(int id)
{
var model = getData(id);
return new ViewAsPdf("PdfCertificate", model)
{
FileName = "Cert.pdf"
};
}
答案 1 :(得分:1)
我的用asp netcore3.1开发的项目遇到了同样的问题,并在安装了“ Microsoft Visual C ++ Redistributable 2017(x86)”后解决了。无论您的操作系统是x64还是x86,请确保安装(x86)!谢谢莎!!
答案 2 :(得分:0)
对我来说,我只需要在服务器上安装 Microsoft Visual C++ Redistributable 2017 (x86)。之前我尝试过其他解决方案,包括在本地主机中安装它们,都没有奏效,我几乎放弃了! ?