我有一个试图从我的 ASP.Net Web 应用程序运行的命令行进程。
当 IIS7.5 应用程序池标识设置为“本地系统”时,将执行命令行代码。当它设置为 ApplicationPoolIdentity 时,它不会。由于使用“本地系统”存在安全风险,我只想授予 ApplicationPoolIdentity 所需的权限,而不是使用本地系统。
如果我正确理解这个答案:IIS AppPoolIdentity and file system write access permissions,用户“IIS AppPool [我的应用程序池]”需要被授予对我的命令行进程将修改的任何文件夹的权限。我已尝试为该用户授予该文件夹的完全权限,但它仍然无法正常工作。我还尝试了 IUSR 和 IIS_USRS 的完全权限。请在下面查看我的代码:
using (Process process = new Process())
{
process.StartInfo.FileName = fileToExecute;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
{
process.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
{
outputWaitHandle.Set();
}
else
{
output.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null)
{
errorWaitHandle.Set();
}
else
{
error.AppendLine(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
int timeout = 1000;
if (process.WaitForExit(timeout) &&
outputWaitHandle.WaitOne(timeout) &&
errorWaitHandle.WaitOne(timeout))
{
Logs logs = new Logs("Finished! - Output: " + output.ToString() + " | Error: " + error.ToString());
logs.WriteLog();
}
else
{
// Timed out.
Logs logs = new Logs("Timed Out! - Output: " + output.ToString() + " | Error: " + error.ToString());
logs.WriteLog();
}
}
}
提前感谢您的帮助!!!