2013-02-21 50 views
2

我有一個使用process.start調用可執行文件(Graphviz)的asp.net應用程序。所有在我的開發環境中運行良好,但是當我轉向生產時,我無法讓程序運行。這是細節。需要哪些權限才能通過asp.net應用程序啓用process.start?

我創建了這個簡單的子來顯示問題。

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load 

    Dim ProcessInfo As ProcessStartInfo 
    ProcessInfo = New ProcessStartInfo 

    'ProcessInfo.Domain = "xxxxxxx" 
    ProcessInfo.UserName = "xxxxxx" 
    Dim PwdString As String = "xxxxxxx" 
    Dim newPass As System.Security.SecureString 
    newPass = New System.Security.SecureString 
    For Each c As Char In PwdString 
     newPass.AppendChar(c) 
    Next c 
    ProcessInfo.Password = newPass 

    'ProcessInfo.FileName = """C:\Windows\System32\Notepad.exe""" 
    'ProcessInfo.FileName = """C:\Test.bat""" 
    ProcessInfo.FileName = """C:\Program Files (x86)\Graphviz2.30\bin\dot.exe""" 
    ProcessInfo.Arguments = " -Kdot -Tsvg C:\Test.dot -pC:\Test.svg" 
    ProcessInfo.RedirectStandardOutput = True 
    ProcessInfo.UseShellExecute = False 
    ProcessInfo.CreateNoWindow = True 

    Dim Process As Process 
    Process = New Process 
    Process.StartInfo = ProcessInfo 
    Process.Start() 

    'Wait until the process passes back an exit code 
    Process.WaitForExit() 

    Try 
     Dim ProcessResults As String = Process.StandardOutput.ReadToEnd 
     Output.Text = ProcessResults 
    Catch ex As Exception 
     Output.Text = ex.ToString 
    End Try 

End Sub 

這裏有三種情況。首先,我正在測試簡單地開始記事本。 - 開發工作 - 生產工程(這是我能得到生產工作的唯一情況)

其次,我創建了一個打開一個記事本文檔簡單的批處理文件。 (記事本C:\ test.dot)

  • 發展工作
  • 生產不起作用

第三,我已經打電話的Graphviz的dot.exe。這是我想要在另一個頁面上工作的。

  • 發展工作
  • 生產不起作用

在所有的情況下,生產不能正常工作,我可以重現此問題 - 如果我添加一個冒充=真到我的web.config ,那麼我不會收到任何錯誤。該頁面運行,如果它是成功的。

  • 如果我不添加冒充配置,但不要添加憑據到ProcessInfo對象,那麼頁面將再次運行沒有錯誤。雖然這個過程並不是從生產開始的。

  • 如果我不添加impersonate或ProcessInfo憑據,那麼我會收到錯誤消息。這是錯誤輸出。

訪問被拒絕

說明:在當前Web請求的執行過程中發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。

Exception Details: System.ComponentModel.Win32Exception: Access is 
denied 

Source Error:  
Line 36:   Process = New Process 
Line 37:   Process.StartInfo = ProcessInfo 
Line 38:   Process.Start() 
Line 39: 
Line 40:   'Wait until the process passes back an exit code 

Source File: C:\Inetpub\vhosts\leapfrogbi.com\httpdocs\test\ProcessStart.aspx.vb Line: 38 

Stack Trace:  
[Win32Exception (0x80004005): Access is denied] 
System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) +2161 
System.Diagnostics.Process.Start() +150 
Test_ProcessStart.Page_Load(Object sender, EventArgs e) in C:\Inetpub\vhosts\leapfrogbi.com\httpdocs\test\ProcessStart.aspx.vb:38 
System.Web.UI.Control.OnLoad(EventArgs e) +91 
System.Web.UI.Control.LoadRecursive() +74 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 

我已經嘗試了多種安全相關的設置。目前我的應用程序池正在以本地管理員身份運行。我也嘗試將所有人添加到管理員組中,試圖查看安全是否是根本問題。

另外,我正在使用Plesk管理我的域。我已經廣泛搜尋可能影響這種情況的任何選項,並且尚未發現。同樣,當進行簡單的調用以啓動記事本時,過程開始在生產中起作用。在沒有更詳細的日誌的情況下很難縮小這個範圍。

非常感謝您提供的任何幫助。這讓我瘋狂。

回答

1

找到您的網站運行的池,並查看下哪個用戶正在運行。

如果你不能做到這一點,你可以運行這個程序,看看您的池正在運行的用戶:

var user = System.Security.Principal.WindowsIdentity.GetCurrent().User; 
var userName = user.Translate(typeof(System.Security.Principal.NTAccount)); 

然後再給允許該用戶可以運行這些文件

參考:How to find out which account my ASP.NET code is running under?

+0

謝謝Aristos。我按照您的建議進行了操作,但應用程序池標識目前是本地管理員組的一部分。 – DataMe 2013-02-21 17:16:06

+0

我驗證了這是Security.Windowsidentity.GetCurrent.User返回的相同用戶。我也繼續前進,並明確給予與請求相關的文件相同的用戶權限,但結果相同。請記住,我可以使用管理員帳戶運行該應用程序,但該過程確實運行,但記事本啓動的第一個示例除外。 – DataMe 2013-02-21 17:42:29

+0

取消我的最後一個。我發現了一個用戶沒有權限的文件。批處理文件運行。我將進一步測試目標exe和報告。 – DataMe 2013-02-21 17:51:16

0

我不使用過程中,使用shell和它運行成功。

  1. 創建包含您的命令的批處理文件。 不要將批次保存在系統文件夾中。

  2. 在IIS中,打開您的網站運行的應用程序池的設置對話框。 將進程池的ID設置爲「localsystem」。

  3. 使用shell(「path \ batchfile」)來執行批處理文件。

相關問題