【发布时间】:2019-08-27 15:50:04
【问题描述】:
我有一个 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);
}
}
这在 Visual Studio 中的本地计算机上运行良好,但是当我部署到我的服务器 (W2K12) 时,我收到以下错误:
Access is denied
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
我在服务器上的 Administrators 和 IIS_IUSRS 组中都有 ExeUsername 引用的帐户。
应用程序池作为不同的帐户运行(因此需要分配一个特定的帐户来运行进程),该帐户也是服务器上管理员和 IIS_IUSRS 的成员。
当我登录服务器并以ExeUsername 运行命令提示符时,我能够执行该进程,因此问题必须与从 IIS 执行有关。
还有什么可能阻止此访问?
【问题讨论】:
-
您的 ApplicationPool 身份是否有权访问
ExeLocation? -
另一种方法是授予 IIS_IUSERS 内置组对您要访问的文件夹的权限。这将为 所有 默认应用程序池提供访问权限,因此请考虑您的用例
-
@kapsiR ApplicationPool 身份也在管理员和 IIS_IUSRS 中
-
@Paul 是的,但是该身份可以访问可执行文件并有权执行该过程吗? Take a look at this question/answer
标签: c# asp.net windows-server-2012