我有一个命令行进程,我试图从我的ASP.Net Web应用程序运行 .
当IIS7.5应用程序池标识设置为“本地系统”时,命令行代码将执行 . 当它被设置为ApplicationPoolIdentity时,它不会 . 由于使用“本地系统”存在安全风险,我只想向ApplicationPoolIdentity授予所需权限,而不是使用本地系统 .
如果我理解这个答案:IIS AppPoolIdentity and file system write access permissions,则需要为用户"IIS AppPool[my app pool]"授予我的命令行进程将修改的任何文件夹的权限 . 我已尝试为该文件夹的此用户授予完全权限,但它仍然无效 . 我还尝试了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();
}
}
}
在此先感谢您的帮助!!!
4 回答
在部署一些Web应用程序时,我有一个类似的问题 . 最后,我们通过授予以下权限解决了我们的权限问题:IIS_USRS,IUSR,LocalMachineName \ Users,LocalMachineName $,SYSTEM,(如果您的应用程序位于域DomainName \ IIS_WPG,DomainName \ Domain Users中)
注意:在Web.config中
事实证明,应用程序池中高级设置下的“加载用户配置文件”设置必须设置为true . 通过这样做,PGP加密程序能够使用该配置文件进行临时数据存储等 .
尝试授予IIS_IUSRS帐户权限 .
此外,请确保该帐户对您正在调用的文件及其引用的任何库具有执行权限 .
我创建了一些测试代码(下面),文件夹秘密只给了系统和管理员权限(不是用户) . 这意味着IIS默认情况下无法查看(已测试) . 然后我给了IIS_IUSERS读取权限,它工作正常 .
(结果显示在屏幕上)
如果您不确定哪些文件需要权限,那么有一个名为process explorer的程序可以让您确切地查看正在使用的内容 .
http://technet.microsoft.com/en-gb/sysinternals/bb896653.aspx
您可以做的是创建新的Windows帐户并分配所需的权限 .
在开始菜单中输入“mmc”,这将打开管理控制台 . 转到“文件”菜单,然后选择“添加/删除管理单元...” . 选择“本地用户和组”,然后选择“添加” .
接下来,以与上一个管理单元相同的方式添加“组策略对象” . 你将最终得到这样的东西:
现在创建新的Windows用户 . 由于您很可能不希望此新用户能够登录localy,因此我们需要设置aditional设置 . 导航到用户权限分配,您应该看到如下内容:
双击“拒绝本地登录”并添加新用户 . 确保您还将设置适当的文件系统权限 .
最后,只需打开IIS管理器并将新用户分配给您的应用程序池 .
最好的祝福