3

我有一个命令行我试图从ASP.Net Web应用程序运行的进程。当使用本地系统应用程序池标识时,进程只能从Web应用程序运行

当IIS7.5应用程序池标识设置为“本地系统”时,命令行代码将执行。当它被设置为ApplicationPoolIdentity时,它不会。由于使用“本地系统”存在安全风险,因此我只想将所需权限授予ApplicationPoolIdentity,而不是使用本地系统。

如果我没有理解这个答案corretly:IIS AppPoolIdentity and file system write access permissions,网友“IIS应用程序池[我的应用程序池]”需要被赋予的权限,我的命令行程序将被修改的任何文件夹。我试图给该用户的完整权限,但它仍然不起作用。我也尝试了对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(); 
       } 
      } 
     } 

在此先感谢您的帮助!

回答

3

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

1

尝试给IIS_IUSRS帐户授予权限。

此外,请确保该帐户对您要调用的文件及其引用的任何库执行权限。

我创建了一些测试代码(如下),文件夹的秘密只有系统和管理员权限(不是用户)。这意味着IIS默认情况下无法查看它(测试)。然后,我给IIS_IUSERS读取权限,它工作正常。

(结果会显示在屏幕上)

Dim compiler As New Process() 
compiler.StartInfo.FileName = "C:\Windows\System32\cmd.exe" 
compiler.StartInfo.Arguments = "/C dir c:\Secret" 
compiler.StartInfo.UseShellExecute = False 
compiler.StartInfo.RedirectStandardOutput = True 
compiler.Start() 
Dim results As String = compiler.StandardOutput.ReadToEnd() 
compiler.WaitForExit() 

如果不能确定哪些文件需要的权限,还有一个程序调用进程资源管理应该让你看到什么是在使用中。

http://technet.microsoft.com/en-gb/sysinternals/bb896653.aspx

+0

我试过给IIS_IUSRS和IUSR的完整权限,但仍然有同样的问题。用这些信息更新我的问题。 – jpsnow72 2013-05-15 12:28:56

+0

事件日志中报告了哪些错误? – 2013-05-16 10:31:42

+0

我在事件日志中看不到任何错误。 – jpsnow72 2013-05-16 10:53:49

0

我有一个类似的问题而回,同时部署了几个web应用程序。最后,我们通过授予以下权限来解决我们的权限问题:IIS_USRS,IUSR,LocalMachineName \ Users,LocalMachineName $,SYSTEM(以及您的应用程序位于DomainName \ IIS_WPG,DomainName \ Domain Users内)

注意:在Web.config内

<authentication mode="Windows" /> 
     <authorization> 
      <deny users="?" /> 
      <allow users="*"/> 
     </authorization> 
<identity impersonate="false" /> 
1

您可以做的是创建新的Windows帐户并分配所需的权限。

在开始菜单中键入“mmc”,这将打开管理控制台。 转到“文件”菜单并选择“添加/删除管理单元...”。 选择“本地用户和组”,然后选择“添加”。

enter image description here

下以同样的方式作为以前的管理单元添加“组策略对象”。你会像这样的东西endup:

enter image description here

现在,创建新的Windows用户。由于您很可能不希望允许此新用户能够在本地登录,因此我们需要设置aditional设置。导航到用户权限分配新建分配FY,你会看到这样的事情:

enter image description here

双击“拒绝本地登录”,并添加新的用户。确保您还将设置适当的文件系统权限。

最后只需打开IIS管理器并将新用户分配给您的应用程序池。

问候

+0

感谢您的回答。我试了一下,仍然无法让PGP软件工作。我给了我认为可能需要的exe和其他目录的新用户权限。 – jpsnow72 2013-05-20 12:09:25

+1

那么很可能你仍然缺少一些权利。如果你能找到任何额外的数据,你可以检查eventlog。在其他情况下,您可以使用诸如Filemon和Regmon之类的工具来确定您需要哪些资源,但由于您在短时间内监视大量数据,所以它可能是一个缓慢的过程......我想最好的选择是联系PGP提供者为您提供运行此软件所需的权限的确切列表。 – 2013-05-20 12:46:29

+0

感谢您的帮助......现在与他们谈论可能需要权限的资源 – jpsnow72 2013-05-20 14:23:03

相关问题