通过 C# 代码调用时,应用程序无法在 Win7、IIS 7.5、ASP.NET4 环境中打开

通过 C# 代码调用时,应用程序无法在 Win7、IIS 7.5、ASP.NET4 环境中打开

我认为这里有一个安全问题,但似乎无法解决。我正在运行 IIS 7.5,应用程序池名为“MyAppPool”。然后我从 C# 代码调用一个程序 PDFCreator.exe,它从 C:\DWF 读取,然后写入 C:\DWF\DWF.PDF。

我已授予 IIS AppPool\MyAppPool 对 PDFCreator.exe 以及 C:\DWF 目录的全部权限。当 C# 创建进程并调用 PDFCreator.exe 时,它​​只会启动一个显示 MyAppPool 为所有者的进程,但从不打开该应用程序。

有人可以补充一下我可能遗漏的安全相关内容吗?

ProcessStartInfo processStartInfo = new ProcessStartInfo(@"c:\program files (x86)\pdfcreator\pdfcreator.exe");
processStartInfo.Arguments = @"/PF""c:\dwf\dwf.dwf"" /NoStart";
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.UseShellExecute = false;
Process process = Process.Start(processStartInfo);
// Read the output stream first and then wait
string output = process.StandardOutput.ReadToEnd();
string errors = process.StandardError.ReadToEnd();
Response.Write(output + errors);

答案1

对于 IIS 应用程序来说,这是一个次优的设计。

桌面应用程序以交互方式运行。

IIS 应用程序作为服务运行 - 不向用户显示用户界面。

您实际上是在使用 IIS 来启动一些后台处理任务(因为您看不到 GUI),这些任务认为它们是前台处理任务。

您在评论中提到的“有点狡猾”正是您在做这件事时可能会遇到问题的原因。 仅举一句话:

然后,该应用程序使用 PDFCreator 的打印机驱动程序打印为 PDF 文件并将其保存到桌面。”

对于 IIS AppPool 用户来说,桌面在哪里?

您可以尝试使用特定的用户帐户(不是IIS 应用程序池\ThisIsAVirtualAccount虚拟应用程序池标识帐户),为其提供特定的配置文件,并将加载用户配置文件设置为 True(应用程序池属性),以确保配置文件文件夹(和打印机驱动程序) 可供该用户使用。

但这一切都将在 IIS 框的后台发生,如果应用程序决定弹出错误对话框,那就完了,它会中断,直到框重新启动。就像我说的,不是最理想的。

相关内容