Posted By

rengber on 01/28/08


Tagged

security aspnet ActiveDirectory


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

smcirish
umang_nine
emregulcan


ASP.Net Code to Get an Active Directory User Name from the Integrated Authentication Principal Name


 / Published in: C#
 

Typically won't work if the ASP.Net service identity (in the machine.config ProcessModel section) is a local account.

  1. private string GetUserName()
  2. {
  3. string retVal = string.Empty;
  4. //Pull the username out of the domain\user string.
  5. retVal = Page.User.Identity.Name.Split('\\')[1];
  6.  
  7. DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + userName +",User");
  8. retVal = (string)userEntry.Properties["fullname"].Value;
  9. return retVal;
  10. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: smcirish on September 12, 2008

How do you just parseout the extra \, to get: domain\user?

You need to login to post a comment.