Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User.Identity.Name casing issue

I'm using ASP.NET MVC 1.0 along with the Oracle ASP.NET Membership Providers. I'm running into a case sensitivity problem.

When a user logs into the system, it appears that the Membership provider sets the User.Identity.Name value to whatever the user typed in. That is, if I created the user as Foo and the user logs in as fOo then everywhere where I use User.Identity.Name on my site, it'll show fOo.

Is there an easy way to work around this? I tried

var user = Membership.GetUser(User.Identity.Name).UserName;

but that gives me the exact same fOo value.

like image 444
cdmckay Avatar asked Aug 15 '26 21:08

cdmckay


1 Answers

As a followup to cdmckay, if you'd want to have the User.Identity.Name correct as well, use

IIdentity newIdentity = new GenericIdentity(properlyCasedUser.UserName);
if (User is RolePrincipal)
    User = new RolePrincipal(((RolePrincipal)User).ProviderName, newIdentity, ((RolePrincipal)User).ToEncryptedTicket());
else
    User = new GenericPrincipal(newIdentity, null);
like image 61
Ruben Avatar answered Aug 17 '26 10:08

Ruben