Andrew Beal
Andrew Beal

Reputation: 427

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

Upvotes: 5

Views: 6244

Answers (1)

dimko1
dimko1

Reputation: 872

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.

Upvotes: 3

Related Questions