我在表单中使用以下代码,但出现错误
public DataTable Passwordexpire()
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal userTemplate = new UserPrincipal(ctx);
userTemplate.AdvancedSearchFilter.AccountExpirationDate(DateTime.Today.AddDays(3), MatchType.LessThanOrEquals);
PrincipalSearcher searcher = new PrincipalSearcher(userTemplate);
foreach (Principal foundPrincipal in searcher.FindAll())
{
UserPrincipal foundUser = (foundPrincipal as UserPrincipal);
if (foundUser != null)
{
DataTable dt = new DataTable();
dt.Columns.Add("AccountName");
dt.Columns.Add("Name");
dt.Columns.Add("Empolyee ID");
dt.Columns.Add("Company");
foreach (SearchResult sResultSet in Dsearch.FindAll())
{
DataRow dr = dt.NewRow();
dr[0] = (GetProperty(sResultSet, "samaccountname"));
dr[1] = (GetProperty(sResultSet, "name"));
dr[2] = (GetProperty(sResultSet, "ExtensionAttribute2"));
dr[3] = (GetProperty(sResultSet, "Company"));
dt.Rows.Add(dr);
}
return dt;
}
}
错误是:
The type or namespace name User Principal could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Principal Searcher could not be found (are you missing a using directive or an assembly reference?)
The name 'MatchType' does not exist in the current context
最佳答案
在存在此 Passwordexpire 方法的 .cs 文件顶部是否有 using System.DirectoryServices.AccountManagement;
指令?
关于C# AD 用户密码过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15308851/