Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow To Programmatically Update Username (Email)How To Programmatically Update Username (Email)
Previous
 
Next
New Post
10/5/2010 12:31 PM
 
Have have custom code that creates users just fine, but am having trouble getting code to work that updates user profiles. Specifically - I have a form that allows the user to update their username - which, in our install, is also their email address.

I have found numerous threads in this forum on this topic, but none of the suggestions are working. I continue to get "A critical error has occurred.
Object reference not set to an instance of an object." errors. I understand that this likely means that some property of the user object is not set correctly, but I can't seem to figure it out.

My first attempt did not work:
theUser = UserController.GetUserById(thePortal.PortalId,Convert.ToInt32(hdn_UserID.Value));
theUser.Username = tb_UserEmail.Text;
theUser.Membership.Username = tb_UserEmail.Text;
theUser.Email = tb_UserEmail.Text;
theUser.FirstName = tb_UserFname.Text;
theUser.LastName = tb_UserLname.Text;
UserController.UpdateUser(thePortal.PortalId, theUser, true);

Nor did this second version (which a take on how I'm adding users):
//update DNN values - email, fname, lname
theUser = UserController.GetUserById(thePortal.PortalId,Convert.ToInt32(hdn_UserID.Value));
theUser.PortalID = thePortal.PortalId;
theUser.IsSuperUser = false;
theUser.FirstName = tb_UserFname.Text;
theUser.LastName = tb_UserLname.Text;
theUser.Email = tb_UserEmail.Text;
theUser.Username = tb_UserEmail.Text;
theUser.DisplayName = tb_UserFname.Text + " " + tb_UserLname.Text;

//Fill MINIMUM Profile Items
theUser.Profile.PreferredLocale = thePortal.DefaultLanguage;
theUser.Profile.TimeZone = thePortal.TimeZoneOffset;
theUser.Profile.FirstName = theUser.FirstName;
theUser.Profile.LastName = theUser.LastName;

//Set Membership
UserMembership theUserMembership = new UserMembership();
theUserMembership.Approved = true;
theUserMembership.CreatedDate = System.DateTime.Now;
theUserMembership.IsOnLine = false;
theUserMembership.Password = tb_UserConfirmPassword.Text;

//Bind membership to user
theUser.Membership = theUserMembership;

//Update the user, ensure it was successful
UserController.UpdateUser(thePortal.PortalId,theUser);

Any advice or code samples you can provide would be GREATLY appreciated. I am pulling my hair out trying to resolve this.

~ Greg
 
New Post
10/5/2010 3:10 PM
 
I am not sure, whether use name can be altered, AFAIR it is a key in MS membership tables and editing might not be supported (and needs to be done in the database).

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
10/5/2010 3:30 PM
 
Greg

3 months ago we had the same request from one of our customers. We spent some time with it, but then customer agreed it is incorrect specification and he does not need to change username. Can you describe why do you need to change username?

Sergey
 
New Post
10/5/2010 3:38 PM
 
Because we are using email addresses as usernames - like many other websites do. And occasionally, for a variety of reasons, a user needs to change their email addresses. Why does the DNN framework not play well with this approach? Is there any work around? I'm happy to code my own solution, but some guidance or documentation would be helpful.
 
New Post
10/5/2010 4:29 PM
 
Greg

On your own risk you can make SQL script and logic and data layer. It should be very easy. This script should change usernames in the two tables:
  • users
  • aspnet_users
But its only on your risk, because problems can appear with time in some hidden sections of site.

Sergey
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow To Programmatically Update Username (Email)How To Programmatically Update Username (Email)


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out