Sha*_*Sha 2 c# rotativa asp.net-core
我在 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)
Run Code Online (Sandbox Code Playgroud)
这是“我的项目”来源
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"
};
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试更改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}
事实证明我需要安装Microsoft Visual C++ Redistributable 2017 (x86)- 在此处下载:https : //visualstudio.microsoft.com/vs/older-downloads/或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"
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4063 次 |
| 最近记录: |