Windows アプリケーションにこのコードを提供し、Windows サーバー 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: 見つかりません
私の物理パスでは、提供された許可は次のとおりです。
Windows認証を次のように設定しても:
<security>
<authentication>
<anonymousAuthentication enabled="false"/>
<windowsAuthentication enabled="true"/>
</authentication>
</security>
RPC を確認しましたが、正常に動作しています
また、この接続のアドレスをDNSに登録することを確認しました
ここMicrosoft Forumsでは、結果のない同じ質問を見ることができます。