运行 Phantomjs.exe 在 Azure 应用服务的 ASP.NET 核心中

Running Phantomjs.exe in a ASP.NET Core in Azure App Service

我有一个 ReSTful API 在 .Net Core 2.0.0 中实现并托管在 Azure 的应用服务中。

我正在尝试让其中一个控制器使用 PhantomJS.exe

生成 PDF 文件

所以我创建了这个方法

控制器的摘要是

        System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
        pProcess.StartInfo.FileName = config.pjlocation;
        pProcess.StartInfo.Arguments = ....; //argument
        pProcess.StartInfo.UseShellExecute = false;
        pProcess.StartInfo.RedirectStandardOutput = true;
        pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows
        pProcess.Start();
        output = pProcess.StandardOutput.ReadToEnd(); //The output result
        pProcess.WaitForExit();

当我 运行 我的控制器在本地使用

时,这很好用
dotnet run

在 windows 机器上,其 .Net Core 版本与 azure 使用的版本相同。

但是在部署到 azure 时遇到 API,该服务长时间无法产生任何响应并返回此错误

The specified CGI application encountered an error and the server terminated the process.

我唯一发现一些痕迹的地方是 azure 中的实时日志流,其中 HTML 被 azure

转储到控制台

HTTP Error 502.3 - Bad Gateway The specified CGI application encountered an error and the server terminated the process.

这里发生了什么,有没有人遇到过类似的问题?我该如何进一步调试?

您可以从 Azure Web App sandbox 得到答案,PhantomJS 在 Azure WebApp 上不支持

Other scenarios that are not supported:

PhantomJS/Selenium: tries to connect to local address, and also uses GDI+.

根据 Azure Web App sandbox,支持以下 PDF 生成器。如果 WebApp 不是唯一的选择,您可以参考 Azure cloudservie 或 Azure VM。

SQL Reporting framework: requires the site to run in Basic or higher (not that this currently does not work Functions apps)

EVOPDF: See http://www.evopdf.com/azure-html-to-pdf-converter.aspx for vendor solution

Telerik reporting: requires the site to run in Basic or higher. More info here

Rotativa / wkhtmltopdf: requires the site to run in Basic or higher.

NReco PdfGenerator (wkhtmltopdf): requires subscription plan Basic or higher