Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove domain from User.Identity.Name in MVC3

I am building an intranet site in MVC3 @Razor. It is utilizing Windows Authentication. The problem I have is that all of the users in the database are listed by UserID. The default action in getting the user information from the Windows context includes the domain (e.g. domain\userid). Is it possible to change this to just get the userid and ignore the domain, without having to write a custom authentication process? Meaning User.Identity.Name is just the userid and not the domain and userid.

EDIT: This is based off of a membership model using the default membership.

EDIT: The problem has nothing to do with the display of the information. The issue is when the system gets the users information from Windows and then goes to get the membership information, can the domain be removed, so only the userid is passed instead of the domain and userid. All I want is to be able to pass the userid to the membership instead of the "domain\userid".

like image 877
user1672410 Avatar asked Dec 08 '22 21:12

user1672410


1 Answers

The following:

User.Identity.Name.Split('\\')[1]; 

will remove the domain part.

like image 51
Forte L. Avatar answered Feb 14 '23 22:02

Forte L.