Windows-7

通過 C# 程式碼呼叫時,應用程序在 Win7、IIS 7.5、ASP.NET4 環境中無法打開

  • January 27, 2012

我認為我在這裡遇到了安全問題,但似乎無法解決。我正在使用名為“MyAppPool”的應用程序池執行 IIS 7.5。然後我從 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);

這是 IIS 應用程序的次優設計。

桌面應用程序以互動方式執行。

IIS 應用程序作為服務執行 - 不向使用者顯示使用者界面。

您實際上是在使用 IIS 來啟動一些認為它們是前台處理任務的後台處理任務(因為您看不到 GUI)。

您在評論中提到的“狡猾”位正是您這樣做可能會遇到問題的原因。隨便挑一句話:

“然後,此應用程序使用 PDFCreator 的列印機驅動程序列印到 PDF 文件並將其保存到桌面。”

對於 IIS AppPool 使用者,桌面在哪裡?

您可以嘗試使用為其提供特定配置文件的特定使用者帳戶(不是IIS AppPool\ThisIsAVirtualAccount虛擬應用程序池標識帳戶),並將載入使用者配置文件設置為 True(應用程序池屬性)以確保配置文件文件夾(以及列印機驅動程序)可供該使用者使用。

但這都是在 IIS 盒子的後台某處發生的所有事情,如果應用程序決定彈出一個錯誤對話框,就是這樣,它會在盒子重新啟動之前被破壞。就像我說的,次優。

引用自:https://serverfault.com/questions/353971