【问题标题】:How to add NT AUTHORITY\IUSR to Administrators group如何将 NT AUTHORITY\IUSR 添加到管理员组
【发布时间】:2012-02-10 01:07:11
【问题描述】:

我想在我的 winforms 应用程序中将 IUSR 帐户添加到该管理员组。下面的代码失败,因为它找不到“NT AUTHORITY\IUSR”的用户:

 DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
 DirectoryEntry administrators = AD.Children.Find("Administrators", "group");
 DirectoryEntry iusr = AD.Children.Find(@"NT AUTHORITY\IUSR", "user");

 administrators.Invoke("Add", new object[] {iusr.Path.ToString()});

我意识到这是个坏主意。我这样做是因为我正在编写一个 winforms 应用程序,它以编程方式在 IIS7 中创建一个新网站,仅用于开发目的。该网站已成功创建,但是每当我尝试加载页面时,ASP.NET 都会显示错误“访问被拒绝”。当我将 IUSR 添加到管理员组时,一切正常。我还能尝试什么?下面是我用来创建新网站的代码:

Site site = servermgr.Sites.Add(websitename, physicalpath, port);
Binding binding = site.Bindings.CreateElement();
string bindinginfo = "*:" + port.ToString() + ":" + hostipaddress;

binding.Protocol = "http";
binding.BindingInformation = bindinginfo;
site.Bindings.Clear();
site.Bindings.Add(binding);

site.Applications.Add(applicationpath, applicationphysicalpath);

site.ApplicationDefaults.ApplicationPoolName = "Default";

servermgr.CommitChanges();

【问题讨论】:

  • 你不能添加一个不存在的用户...你的问题到底是什么?
  • 这是一个的想法
  • @Yahia IUSR 是有效的内置安全主体
  • 我不知道你想做什么,但不管它是什么,这一定是一种非常危险的方法。允许匿名请求拥有完整的管理员权限是彻底灾难的秘诀。
  • 附加字符:应该是下划线后跟机器名

标签: c# winforms active-directory directoryentry


【解决方案1】:
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry administrators = AD.Children.Find("Administrators", "group");

administrators.Invoke("Add", new object[] {"WinNT://NT AUTHORITY/IUSR"});

【讨论】:

    【解决方案2】:

    正确的解决方案是要求对页面进行身份验证。然后,这会提示您登录浏览器;如果您使用适当授权的帐户,则该页面将能够创建新网站。

    IIS7 允许您从(例如)ApplicationHost.config 进行配置,而以前的版本需要您编辑元数据库(通常从​​ IIS 管理器)。

    编辑:根据身份验证、浏览器和网络配置,可以安排浏览器使用您的域帐户自动登录页面。

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多