Is it possible to save a custom string in an Active Directory user? For example a string that contains a list of user-roles
separated with some semicolon? For example a DirectoryEntry
contains something like a userRoles
that has the value read;write;
or something similar?
I'm trying to set and access those information using c#.
Thanks a lot!
You basically have three options for doing this.
In all cases, you would query these fields (eg. using System.DirectoryServices.AccountManagement) to interact with the data. Active Directory isn't meant to be a transactional database though. If you need to store custom data about your users that can be accessed by your applications, you would most likely be better off taking a look at something like ASP.NET Membership and Roles (older but proven tech) or ASP.NET Identity. Since I am more familiar with Membership and Roles I will use it as an example. The authentication (membership) and authorization (roles) aspects are separate, meaning that your users could be authenticated using AD using the built-in provider, but then use a custom role provider implementation that (for example) checked their role membership against a SQL database, web service, XML file, or whatever else you could dream up. You can even check against multiple sources (such as AD groups AND a SQL database), implement caching if performance is an issue, and so-on.
Active Directory has some drawbacks, such as:
So while it is possible to store custom data in AD, it is often undesirable, labor-intensive, and unsafe.