从 ASP.NET 网站拒绝访问启动过程

Pau*_*aul 5 c# asp.net windows-server-2012

我有一个 ASP.NET MVC4 网站,我正在尝试在服务器上执行一个进程。代码如下:

ProcessStartInfo startInfo = new ProcessStartInfo()
{
    FileName = ExeLocation,
    Arguments = string.Format("\"{0}\"{1}", ScriptLocation, Arguments),
    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    WorkingDirectory = AppDir,
    CreateNoWindow = true,
    UserName = ExeUsername,
    Password = ExePassword,
    Domain = ExeDomain
};

using (Process process = Process.Start(startInfo))
{
    using (StreamReader reader = process.StandardOutput)
    {
        output = reader.ReadToEnd();
    }
    using (StreamReader reader = process.StandardError)
    {
        error = reader.ReadToEnd();
    }
    process.WaitForExit();
    if (process.ExitCode != 0)
    {
        throw new Exception(string.IsNullOrEmpty(output) ? error : output);
    }
}
Run Code Online (Sandbox Code Playgroud)

这在 Visual Studio 的本地机器上运行良好,但是当我部署到我的服务器 (W2K12) 时,我收到以下错误:

Access is denied   
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
Run Code Online (Sandbox Code Playgroud)

我在服务器上的AdministratorsIIS_IUSRSExeUsername中都引用了该帐户。

应用程序池作为一个不同的帐户运行(因此需要分配一个特定的帐户来运行该进程),它也是服务器上管理员和 IIS_IUSRS 的成员。

当我登录服务器并以 身份运行命令提示符时ExeUsername,我能够执行该过程,因此问题必须与从 IIS 执行有关。

还有什么可能阻止此访问?

小智 1

  1. 右键单击应用程序池
  2. 点击高级设置
  3. 身份
  4. 自定义账户
  5. 设置用户名和密码

如果您有域,请小心使用域\用户名作为用户名
,并访问部署文件夹。