我有一个在 .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.
这里发生了什么,有人遇到过类似的问题吗?如何进一步调试?
最佳答案
您可以从 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/