Search code examples
c#asp.net-mvc-4ldap

Extract username from DOMAIN\Username c#


I have implemented an application that authenticates users against active directory using LDAP. Since users are being authenticated from different domains, they log in by DOMAIN\UserName. After being logged in, I capture the username by using User.Identity.GetUserName() however this, of course, returns DOMAIN\UserName. What I need to do here now is to extract the UserName from the string returned. Any help will be appreciated.


Solution

  • What about User.Identity.GetUserName().Split('\\')[1] ?