c# - How to query Active Directory for a user whose name contains a dollar sign ($)? -


i have code snippet searches locally-defined windows user :

using (principalcontext context = new principalcontext(contexttype.machine)) {     using (principal queryfilter = new userprincipal(context) { name = accountname }) {         using (principalsearcher searcher = new principalsearcher(queryfilter)) {             var principal = searcher.findone();             ...         }     } } 

the code works fine if accountname contains normal alphanumerics, (eg "testuser"). however, if name contains dollar sign (eg "test$user"), findone() returns nothing.

i suspect $ being interpreted kind of metacharacter. there way of preventing happening, interpreted literally?

if you're looking single entry - try this:

userprincipal user = userprincipal.findbyidentity(context, "test$user");  

maybe works?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -