有没有人有幸在 Windows 域上查询/更改 SPN? Google 上的大多数点击都与 SQL 相关:我自己找不到任何关于如何执行此操作的信息。最重要的事情是查询 SPN 配置并检查重复项。
根据 Arnout 的说法,我编写了以下代码:
static void Main(string[] args) {
ValidateSPN("K2Server/jonathand-vpc:5252");
}
static void ValidateSPN(string spn) {
const string queryFormat = "(ServicePrincipalName={0})";
using (Domain localDomain = Domain.GetCurrentDomain()) {
using (DirectorySearcher search = new DirectorySearcher(localDomain.GetDirectoryEntry())) {
search.Filter = string.Format(queryFormat, spn);
search.SearchScope = SearchScope.Subtree;
SearchResultCollection collection = search.FindAll();
if (collection.Count > 1)
throw new Exception("Duplicate SPNs found.");
else if (collection.Count == 0)
throw new Exception("No such SPN");
}
}
}
最佳答案
看起来此信息存储在 servicePrincipalName
AD 属性中。参见 this page了解更多信息,特别是“使用 LDIFDE 搜索”部分。
关于c# - 在没有 SetSPN 的情况下查询/更改 Windows 域上的 SPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/416241/