views:

162

answers:

3

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.

A: 

Here's a solution I found but I feel like it should be more direct than this:

MembershipUser user = _provider.GetUser(userName, false);
MembershipUser properlyCasedUser = _provider.GetUser(user.ProviderUserKey, false);
cdmckay
A: 

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);
Ruben
It seems silly that they don't just have a `.UserName = Foo` and a `.LoginUserName = fOo` or something to that effect.
cdmckay
A: 

Check this out: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=104933 .. And this is from 2004, come on Microsoft... :-(

Morten
Status: Closed (Won't Fix)
cdmckay