Posted By

rengber on 01/28/08


security aspnet ActiveDirectory

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


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];
  7. DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + userName +",User");
  8. retVal = (string)userEntry.Properties["fullname"].Value;
  9. return retVal;
  10. }

Report this snippet  


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.