简体   繁体   中英

Changing HttpContext.Current.User.Identity.Name after User is logged in

I'm currently working on a ASP MVC application. And was wondering if there is a way of changing HttpContext.Current.User.Identity.Name once the user has logged in.

I want to be able to do this to allow the user to change his/her username, and so need HttpContext.Current.User.Identity.Name to be changed once they have done that.

Any help would be great

I believe you can not do this:)

It is filled during authentication. Simpliest solution is when user changes username - log him out, and ask for login.

Update

It will work only with custom provider. If you are using standard one, i believe it can't be changed at all.

As an alternative solution you can try to do next: When user tries to change his name: 1. Create new user 2. abandon session 3. remove old user 4. change all data which related to user to a new account 5. log him in once again with new user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM