2017-12-29 2 views
1

Ich habe mit dem folgenden zu kämpfen, das ist, was ich jetzt habe und es funktioniert aber.Wechsel zwischen sicheren und nicht sicheren DirectoryServices.AccountManagement.PrincipalContext

public PrincipalContext getPrincipalContext(bool secured) 
{ 
    PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, 
     secured ? DomainName + ":636" : DomainName, 
     Container, 
     secured ? ContextOptions.SecureSocketLayer | ContextOptions.Negotiate : ContextOptions.SimpleBind, 
     userName, 
     password); 
    return oPrincipalContext; 
} 

wollen wie dieses Ich denke

secured ? PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, 
      DomainName + ":636", 
      Container, 
      ContextOptions.SecureSocketLayer | ContextOptions.Negotiate 
      userName, 
      password); 
     : 
      PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, 
      DomainName, 
      Container, 
      ContextOptions.SimpleBind); 
    return oPrincipalContext; 

etwas zu tun, das möglich ist, aber es nicht bekommen kann zu kompilieren. Kann mir jemand mit dem richtigen Weg helfen?

Antwort

0

Mai dieses:

PrincipalContext oPrincipalContext = secured ? 
     new PrincipalContext(ContextType.Domain, 
      DomainName + ":636", 
      Container, 
      ContextOptions.SecureSocketLayer | ContextOptions.Negotiate 
      userName, 
      password); 
     : 
      new PrincipalContext(ContextType.Domain, 
      DomainName, 
      Container, 
      ContextOptions.SimpleBind); 

oder warum Sie nicht nur if, else

+0

verwenden, das ist genau das, was ich gesucht –

Verwandte Themen