如何授权用户使用Active Directory和Asp.net Web API

时间:2016-03-08 08:21:15

标签: c# asp.net active-directory asp.net-web-api2

我设法通过Active Directory使用此代码验证用户

 DirectoryEntry entry = new DirectoryEntry(ADPath, domainAndUsername, password);
            object obj = entry.NativeObject;
            DirectorySearcher search = new DirectorySearcher(entry);
            search.Filter = "(SAMAccountName=" + username + ")";
            search.PropertiesToLoad.Add("cn");
            SearchResult result = search.FindOne();
            if (null == result)
            {
                return "false";
            }

如果用户通过身份验证后我想为此用户创建授权规则以阻止访问我拥有的ApiControllers

我该怎么做?

感谢您的帮助!

0 个答案:

没有答案