2010-11-02 4 views
0

У меня есть интрасеть, которая получает текущий зарегистрированный пользователь через активный каталог. Когда пользователь заблокирован, они получают приглашение Windows, чтобы ввести свое имя пользователя и пароль. Есть ли способ для меня поймать это и перенаправить их на страницу, где их попросят снова ввести свои учетные данные или сообщить им, что их учетная запись может быть заблокирована и обратиться в службу поддержки?asp.net active directory intranet

ответ

0

В приложении, как только вы захватите пользователя, вошедшего в сделать IsAccountLocked метод ниже

public bool IsAccountLocked(string sUserName) 
{ 
    UserPrincipal oUserPrincipal = GetUser(sUserName); 
    return oUserPrincipal.IsAccountLockedOut(); 
} 

public UserPrincipal GetUser(string sUserName) 
{ 
    PrincipalContext oPrincipalContext = GetPrincipalContext(); 

    UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName); 
    return oUserPrincipal; 
} 

public PrincipalContext GetPrincipalContext() 
{ 
    PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ContextOptions.SimpleBind, sServiceUser, sServicePassword); 
    return oPrincipalContext; 
} 

Это использование System.DirectoryServices.AccountManagement для использования только System.DirectoryServices вы можете сделать это

public bool IsAccountLocked(DirectoryEntry oDE) 
{ 
    return Convert.ToBoolean(oDE.InvokeGet("IsAccountLocked")); 
} 
public DirectoryEntry GetUser(string sUserName) 
{ 
    //Create an Instance of the DirectoryEntry 
    oDE = GetDirectoryObject(); 

    //Create Instance fo the Direcory Searcher 
    oDS = new DirectorySearcher(); 

    oDS.SearchRoot = oDE; 
    //Set the Search Filter 
    oDS.Filter = "(&(objectClass=user)(sAMAccountName=" + sUserName + "))"; 
    oDS.SearchScope = SearchScope.Subtree; 
    oDS.PageSize = 10000; 

    //Find the First Instance 
    SearchResult oResults = oDS.FindOne(); 

    //If found then Return Directory Object, otherwise return Null 
    if (oResults != null) 
    { 
     oDE = new DirectoryEntry(oResults.Path, sADUser, sADPassword, AuthenticationTypes.Secure); 
     return oDE; 
    } 
    else 
    { 
     return null; 
    } 
} 
private DirectoryEntry GetDirectoryObject() 
    { 
     oDE = new DirectoryEntry(sADPath, sADUser, sADPassword, AuthenticationTypes.Secure); 
     return oDE; 
    } 

для полной реализации вы можете пойти в http://anyrest.wordpress.com/2010/06/28/active-directory-c/ или http://anyrest.wordpress.com/2010/02/01/active-directory-objects-and-c/

+0

спасибо, я попробую попробовать – Migs

Смежные вопросы