c# - 在 Azure 应用服务的 ASP.NET Core 中运行 Phantomjs.exe

标签 c# azure asp.net-core phantomjs asp.net-core-webapi

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

我正在尝试让其中一个 Controller 使用 PhantomJS.exe 生成 PDF 文件

所以我创建了这个方法

Controller 的摘要是

        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();

当我使用本地运行 Controller 时,这效果很好

dotnet run

在一台与 azure 使用的 .Net Core 版本相同的 Windows 计算机上。

但是在部署到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.

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

error

最佳答案

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

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 or 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

关于c# - 在 Azure 应用服务的 ASP.NET Core 中运行 Phantomjs.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47652339/

相关文章:

azure - Azure 应用服务上部署的网站的文件管理器中缺少大量文件

docker - 在 Docker 中以自定义用户身份运行 ASP.NET Core 应用程序

c# - 如何在 Visual Studio 2022 中使用日期/时间更改 AssemblyInfo.cs AssemblyVersion 并每天将修订增加一

c# - 从 xml 检索值 - C#

azure - 多个 Azure EventHub 触发器可触发 Azure Function 应用程序中的单个函数

azure - 如何判断 Azure CloudQueue.AddMessage 是否成功?

asp.net-core - .Net Core 5 Post Response 返回不正确的内容类型 : application/json

azure - 如何从 vNext Build 运行 Azure WebJob?

c# - 防止立即触发 Quartz.Net 事件

c# - 在 WPF 3D 中可视化世界系统的坐标轴