Process.Start in Azure Website

半城伤御伤魂 提交于 2019-11-27 08:09:11

问题


I have an ASP.NET MVC 5 app where I need to invoke wkhtml2pdf.exe in my Azure website using Process.Start. Locally everthing works fine. But it seems my app stuck at Process.Start line. Is starting a process is supported on Azure?


回答1:


ramiramilu's answer is actually not correct. You can run any exe you want (check this for example). The problem you are hitting is not in running an exe, it's something specific to wkhtml2pdf.exe itself. That exe uses a bunch of GDI+ calls on Windows for rendering the PDF and that is what's not allowed in Azure Websites sandbox (the GDI+ calls, not running an exe).

Using a WebJob won't help either because WebJobs run in the same context as the site which means under the same sandbox.

Edit:

There is nothing special to how you would launch an external process on Azure Websites than how you would do it normally with C#. Again the problem you are facing is with wkhtml2pdf.exe and not with the general concept of launching a process.

Here is a sample that you can try that launches cmd.exe and reads what is written on stdout

var processStartInfo = new ProcessStartInfo()
{
    Arguments = "/c echo \"test\"",
    FileName = @"c:\windows\system32\cmd.exe",
    RedirectStandardOutput = true,
    UseShellExecute = false
};

var process = Process.Start(processStartInfo);

using (var streamReader = new StreamReader(process.StandardOutput.BaseStream))
{
    ViewBag.MessageFromExe = streamReader.ReadToEnd();
}

ViewBag.MessageFromExe will have the value "test" you can verify that on your view and you can run that just fine in Azure Websites




回答2:


You can use an alternative way to do PDF generation that will work in Azure WebApps. See this blog.



来源:https://stackoverflow.com/questions/28293505/process-start-in-azure-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!