jeudi 23 juin 2016

Can you set HttpContext.Current.UserIdentity.Name with reflection?

I am trying this:

typeof(FormsIdentity)
    .GetField("Name", BindingFlags.Instance | BindingFlags.NonPublic)
    .SetValue(HttpContext.Current.User.Identity, newUsername);

but typeof(FormsIdentity).GetField("Name", BindingFlags.Instance | BindingFlags.NonPublic) returns null. What I am trying to do is allow a user to change their username.





Aucun commentaire:

Enregistrer un commentaire