简体   繁体   English

如何通过 asp.net 核心获取当前计算机的域?

[英]How can I get the current computer´s domain via asp.net core?

In .NET 4.7.2 I can get the current computer domain在 .NET 4.7.2 可以得到当前计算机域

using System.DirectoryServices.ActiveDirectory;

using (var lDomain = Domain.GetComputerDomain())
{
    [...]
}

How can I get the current computer´s domain via asp.net core?如何通过 asp.net 核心获取当前计算机的域?

According to your description, I suggest you could try to use IPGlobalProperties to get your current domain.根据您的描述,我建议您可以尝试使用IPGlobalProperties来获取您当前的域。

It provides information about the.network connectivity of the local computer.它提供有关本地计算机网络连接的信息。

      var re =   System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;

Result:结果:

在此处输入图像描述

Based on some searches, you should be able to install https://www.nuget.org/packages/System.DirectoryServices and use that class.根据一些搜索,您应该能够安装https://www.nuget.org/packages/System.DirectoryServices并使用 class。

In .NET Core these classes are not part of the framework, requiring you to install Nuget packages for them.在 .NET Core 中,这些类不是框架的一部分,需要您为它们安装 Nuget 包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM