Retrieving AD username without domain

843 Views Asked by At

I am currently switching an old c# intranet application which used Forms authentication and Profiles (SQL) to authenticate and keep track of users. However, now I am converting it to work with Windows authentication.

I have got most of it working but the issue now is that I have to handle the new username schema. For example, previously, usernames were saved like so for a John Doe: jdoe. Now, since I am using windows authentication, I receive the username as EXAMPLE\\jdoe (where EXAMPLE is the domain name).

I understand that I can simply split the received username to just get jdoe -- and I had been doing that for testing purposes -- but that solution is only feasible where I am working only with strings. There are instances where I need to work directly with the User object (System.Security.Principal.IPrincipal.Page.User) like in case I need to use the User.IsInRole() method which is only accessible to User objects and not strings.

Now my question is, can I set this is up in some way that by default User.Identity.Name returns jdoe instead of EXAMPLE\\jdoe while still using Windows authentication?

One bruteforce solution would be to recreate every user with the domain prepended and handle the domain and username split in edge cases. But I'd rather not go that route unless absolutely necessary.

0

There are 0 best solutions below