Problem with user .Identity.Name

I am using ASP.NET MVC 1.0 along with Oracle ASP.NET membership providers. I ran into a case sensitivity problem.

When a user logs in, it turns out that the membership provider sets the value User.Identity.Nameregardless of what the user entered. That is, if I created the user as Foo, and the user is registered as Foothen wherever I use User.Identity.Nameon my site, he will show Foo.

Is there an easy way around this? I tried

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

but it gives me the same meaning Foo.

+3
source share
3 answers

cdmckay, , .Identity.Name ,

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);
+1

, , , , :

MembershipUser user = _provider.GetUser(userName, false);
MembershipUser properlyCasedUser = _provider.GetUser(user.ProviderUserKey, false);
0

Source: https://habr.com/ru/post/1714923/


All Articles