Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Username ASP.net MVC 3 Membership

I am running a ASP.net MVC 3 web application, and using the Membership Provider. I would like to know if its possible to allow the user (or administrator) to change an existing accounts username? I have not found a way to do this. The username is not an email address, but is validated on its uniqueness prior to my attempt at assigning the new name.

Any help would be appreciated!

like image 867
Blyde Avatar asked Sep 13 '12 20:09

Blyde


1 Answers

The membership provider does not provide a method to update the username. You will either need to extend the membership providers UpdateUser method or directly interact with the membership tables to allow this change. However you approach this, keep in mind a few items

  1. On update, you will need to check uniqueness of the username much like what happens when a user is created.

  2. If the user is logged in and changes their username, you will either need to force them logout and log back in or reissue the AuthenticationTicket cookie. The reason being, if they change their username, then the authTicket cookie stored username and the actual username not longer match. If you use HttpContext.Identity.User.Name to query your datastore or check authorization to content, you will no longer return any results as that username no longer exists.

like image 105
Tommy Avatar answered Nov 12 '22 20:11

Tommy