asp.net - 通过 ASP.NET 应用程序启用 process.start 需要哪些权限?

标签 asp.net permissions process.start

我有一个 asp.net 应用程序,它使用 process.start 来调用可执行文件 (Graphviz)。一切在我的开发环境中运行良好,但是当我转向生产时,我无法运行该流程。这是详细信息。

我创建了这个简单的子程序来显示问题。

    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。这就是我试图在另一个页面中工作的内容。

  • 开发工作
  • 生产无法进行

在所有生产不起作用的情况下,我都可以重现此行为 - 如果我将 impersonate = true 添加到我的 web.config,那么我不会收到任何错误。页面运行就像成功一样。

  • 如果我不添加模拟配置,但将凭据添加到 ProcessInfo 对象,则页面将再次运行而不会出现错误。不过,该过程尚未在生产中启动。

  • 如果我不添加模拟或 ProcessInfo 凭据,则会收到错误消息。这是错误输出。

Access is denied

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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 来管理我的域。我已经广泛搜索了可能影响这种情况的任何选项,但尚未找到。同样,当进行简单的调用来启动记事本时,进程启动确实可以在生产中工作。如果没有更详细的日志,很难缩小范围。

预先感谢您提供的任何帮助。这让我发疯。

最佳答案

找到您的网站在其下运行的池,并查看在哪个用户下运行。

如果您不能这样做,您可以运行此代码来查看您的池正在运行的用户:

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?

关于asp.net - 通过 ASP.NET 应用程序启用 process.start 需要哪些权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15000265/

相关文章:

c# - 如何在c#中读取html表格

java - 如何向外部后端请求权限?

c# - 缓存 WCF 服务的问题 - "AspNetCacheProfileAttribute can only be used with GET operations"

asp.net - 如何使用 Identityserver4 请求刷新 token

php - 无法删除用 PHP 创建的目录或文件(又名权限 hell )

java - getExternalStorageDirectory 和 getExternalStoragePublicDirectory 之间的区别?

c# - 是否可以打开 regedit 并使用 process.start 直接导航到特定键?

xna - Process.Start 在 XNA 游戏中打开太多浏览器

c# - Process.Start ("echo", "%cd%") 抛出 W32Exception 找不到文件

c# - 如何为客户获取正确的时区