使用模拟帐户访问 IIS IP 阻止列表

Access IIS IP Blocked List using impersonation account

在我的 ASp Net web 表单应用程序中,模拟已启用,并设置了用户名和密码。 <identity impersonate="true" userName="impersonationaccount" password="*************" />

该网站的安全功能之一是它会检查 IIS 的阻止 IP 地址列表。问题是这个模拟帐户需要生产服务器上的管理员权限(windows 帐户访问权限),这是不需要的。

出现的错误是这样的:

Filename: redirection.config
Error: Cannot read configuration file due to insufficient permissions

这是从IIS访问IP黑名单的代码。

/// <summary>
/// Constructor
/// </summary>
public IPBlocker(string siteName)
{
    this.serv = new ServerManager();
    this.config = this.serv.GetApplicationHostConfiguration();
    this.ipSecuritySection = this.config.GetSection("system.webServer/security/ipSecurity", siteName);
    this.ipSecurityColl = this.ipSecuritySection.GetCollection();
}

在它试图获取 ipSecurity 部分的那一行抛出错误。

有没有一种方法可以通过提升权限以编程方式访问此文件,以便能够读取此文件?

如果您需要更多信息,请告诉我。

正确的方法是创建远程服务应用程序。这将执行以下操作:

  • 配置了适当的安全权限。
  • 将确保您不会给 Web 应用程序过多的控制权。

安全是非常棘手的领域之一,但您应该尝试遵守一个细节:

You shouldn't provide too much control to an application, it is better to abstract or ask for the control that you need, when you need it. Otherwise you risk your application exposing other areas within the system.

由于您试图通过 ServerManager.dll 直接与 Internet 信息系统 (IIS) 交互,因此您需要 完全权限。这是你的网络应用程序不应该有的东西。您应该将它们分开,这样您的 Web 应用程序可以保留其当前权限,而服务将拥有完整的调用权限。

您可以通过多种方法来实现您的服务。

一种方法是 Windows Communication Foundation (WCF),可以在我的回答中找到这些信息和教程链接 here