我正在ASP.NET Core 2.1.1项目中使用最新的rotativa.net core程序集。裸体(
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核心1.0编译的:
这里有代码可以将rotativa.net core从.NET核心1更新为.NET核心2.0:
https://github.com/aaxelm/Rotativa.NetCore/pull/1/files?diff=split
因此,我下载了rotativa源代码并相应地更新到.NET核心2.0,引用了新的程序集。问题仍然存在。
我也查过分期付款。Rotativa文件夹授予IIS执行权限(运行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_