asp.net - 使用本地系统应用程序池标识时,进程仅适用于 Web 应用程序

标签 asp.net permissions iis-7.5 windows-server-2008-r2 application-pool

我有一个命令行进程,我正在尝试从 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();
                }
            }
        }

预先感谢您的帮助!!!

最佳答案

事实证明,应用程序池中“高级设置”下的“加载用户配置文件”设置必须设置为 true。通过这样做,PGP 加密程序能够使用该配置文件进行临时数据存储等。

关于asp.net - 使用本地系统应用程序池标识时,进程仅适用于 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16485692/

相关文章:

c# - 想要在 Asp.net Web 应用程序上运行 WPF 应用程序。

.net - 关于 MVC 自定义错误和本地堆栈跟踪的 web.config 中的 <httpErrors> 问题

asp.net-mvc - 编辑 Web.config 文件是否会触发重叠回收或应用程序池的启动+停止?

asp.net - IIS/ASP/ASP.net : How to structure web-site to expose mobile version

asp.net - 图像大小不适用于 mozilla 和 IE

c# - 一到无穷正则表达式

ios - 如果他们仍然拒绝,请偶尔请求 iOS 权限

linux - RHEL4/Mono x86_64 上的 System.UnauthorizedAccessException

windows-7 - cwRsync 在 Windows 7 上忽略 "nontsec"

windows - ASP.NET MVC 站点在 LAN 上运行速度非常慢,但在本地主机上运行良好