How can i check that the current user logged onto the machine is an active directory user and also part of the application?
I am building an extension to a legacy application which authenticates based on AD. The database has ad_user_name and i want to compare the ad_user_name with the username actually held in active directory.
IF the usernames are the same then my edit view is accessible. If the users are different then something went wrong and they cant see anything.
EDIT: there is a possibility that the server only runs .NET 2.0
If your using .net 3.5 use this code instead.
To authenticate a user:
If you need to find the user to R/W attributes to the object do this:
This is using the
System.DirectoryServices.AccountManagementnamespace so you’ll need to add it to your using statements.If you need to convert a UserPrincipal object to a DirectoryEntry object to work with legacy code you can do this: