Zum Hauptinhalt gehen

Get Current User - query Active Directory for email address

Kommentare

9 Kommentare

  • Sebastian Mariendal Kristensen

    Use PrincipalContext from the System.DirectoryServices.AccountManagement namespace.

    I found this exsample and modified it to get the rigth office name and full name on map prints.

    http://www.codeproject.com/Articles/38344/Using-System-DirectoryServices-AccountManagement

     

     

    0
  • Permanently deleted user

    Hi Sebastian

    Is there any chance you could post your code for implementing the search in active directory after getting the current user ID? We would like to do something similar but my coding skills aren’t at the level to understand and apply the code in the link you posted.

    Thanks

    Shaun

    0
  • Sebastian Mariendal Kristensen

    I Have copyed the workflow to my public dropbox.

    You can find it here

    https://dl.dropboxusercontent.com/u/41049387/GeoCortex/GetAdName.xaml

     

    Here you can see what you can get from the userprincipal class

    /customer/servlet/servlet.FileDownload?file=00P6000000e88ZoEAI

    0
  • Permanently deleted user

    thanks sebastian, works perfectly 

    0
  • Permanently deleted user
    Hi, 

     

    I'm trying to get the emailaddress of the current user using System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress and it works in the Workflow simulator, but when running it on the server I get this error: 

     

    << Unhandled exception: 'Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.' in activity '1.654: Assign'. >> 

     

    I then tried it in 2 steps: 

     

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

     

    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "UserName"); 

     

    But get another error:  

     

    << 'Type 'System.DirectoryServices.AccountManagement.PrincipalContext' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute. ...>> 

     

    I don't see how I can do this in the workflow designer. 

     

    ?Any help is welcome. 

     

    Patricia Bongaerts 

     

    Port of Antwerp
    0
  • Kevin Penner
    Hi Patricia,

     

    You are using AD to secure the app right? If so, I have a colleague who did this the other day, I'll forward him this thread and see if he can help out.

     

    -Kevin
    0
  • Permanently deleted user
    Hi Patricia,

     

    I have recently worked on a similar AD email authentication in the workflow designer.

     

    Here is what I did to retrieve the AD email claim:
    1. Use a GetCurrentUser activity to obtain their list of claims.
    2. Use an Assign activity to find the AD email claim as follows:  iEnumUserClaims.Where(Function(x) x.Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").FirstOrDefault()
    3. Use an If activity to confirm that the user has an AD email claim.
    Here is a screenshot of the activities used:

     

    _img_ alt="User-added image" src="https://latitudegeo--c.na53.content.force.com/servlet/rtaImage?eid=907f2000000kA8l&feoid=Body&refid=0EMf2000000fyR9"_/_img_

     

    Let me know if you have any questions.

     

    -Matt
    0
  • Permanently deleted user
    Hi Matt,

     

    This works perfectly! Thank you so much.

     

    Patricia
    0
  • Hwa Saup Lee
    @Mattew  it may couple years old post.  I was scratching my head to get AD email of current user.  your post solved the problem.  thanks. 
    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.