需要Windows服务器中的DNS权限

时间:2020-01-23 13:43:08

标签: c# asp.net dns wmi system.management

我为Windows应用程序提供了此代码,并能够在Windows Server 2019上添加DNS区域。

string site = "domain.com";
ConnectionOptions co = new ConnectionOptions();
ManagementScope _scope =new ManagementScope(String.Format(@"\\{0}\root\MicrosoftDNS", System.Net.Dns.GetHostName()), co);
_scope.Connect();
ManagementObject mc = new ManagementClass(_scope, new ManagementPath("MicrosoftDNS_Zone"), null);
mc.Get();
ManagementBaseObject parameters = mc.GetMethodParameters("CreateZone");
parameters["ZoneName"] = site;
parameters["ZoneType"] = (UInt32) DNSServer.NewZoneType.Primary;
parameters["DsIntegrated"] = 0; //false
ManagementBaseObject createdEntry = mc.InvokeMethod("CreateZone", parameters, null);

当我尝试在Web应用程序(asp.net)上使用当前代码时,它不起作用:

System.Management.ManagementException:通用故障

当我将@"\\{0}\Root\MicrosoftDNS"更改为@"\\{0}\root\cimv2"时,会出现此错误:

System.Management.ManagementException:找不到

在我的物理路径上,提供了任何许可:

enter image description here

即使我将Windows身份验证设置为:

<security>
      <authentication>
        <anonymousAuthentication enabled="false"/>
        <windowsAuthentication enabled="true"/>
      </authentication>
    </security>

enter image description here

我也在这里在WMI上设置了权限 enter image description here

即使我检查了RPC,也可以正常工作

enter image description here

我还选中了在DNS中注册此连接的地址

enter image description here

Microsoft Forums上,您可能会看到相同的问题而没有结果。

0 个答案:

没有答案