Administrator change users email without being logged in as user?

Last post 06-26-2008 4:55 PM by ClarkNK. 6 replies.

Sort Posts:

  • Administrator change users email without being logged in as user?

    06-26-2008, 12:38 AM
    • Member
      99 point Member
    • ClarkNK
    • Member since 05-24-2008, 11:56 PM
    • Upstate NY
    • Posts 202

    If an administrator has a member's UserName but not his password, is there a simple way the administrator can change the member's email? I am using the default membership provider which stores the email and lowered email in the aspnet_membership table.

    Can someone show me an example of vb code  to do this (if it is possible)? 

    CHO, Homepage Doctor
    http://www.homepagedoctor.com/Tutorials.htm
  • Re: Administrator change users email without being logged in as user?

    06-26-2008, 1:13 AM
    Answer
    • Star
      7,726 point Star
    • satalaj
    • Member since 11-28-2007, 5:41 AM
    • Pune
    • Posts 1,526
    Hi,
     Try below code

    protected
    void Page_Load(object sender, EventArgs e)

    {

    if(!Page.IsPostBack)

    {

    MembershipUserCollection mu = new MembershipUserCollection();mu = Membership.GetAllUsers();

     

    foreach(MembershipUser user in mu)

    {

    ListBox1.Items.Add(user.UserName);

    }

    ListBox1.DataBind();

    }

     

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

    MembershipUser user = Membership.GetUser(ListBox1.SelectedValue);

    user.Email = TextBox1.Text;

    Membership.UpdateUser(user);

     

    }

    Satalaj

  • Re: Administrator change users email without being logged in as user?

    06-26-2008, 1:44 AM
    Answer
    • Member
      473 point Member
    • masfenix
    • Member since 01-08-2007, 7:28 AM
    • Toronto
    • Posts 188

    The Membership object has shared functions that help you do this.

    Consider the following VB code:

     

    1    Dim user As MembershipUser
    2    user = Membership.GetUser(username)
    3    user.Email = "newEmail"
    4    Membership.UpdateUser(user)
    5    
    6    
    

     

    You also have the Membership.GetUserNameByEmail function that gets the username based on their old email. 

    Visit http://www.dailytip.net to view your daily tip@!
  • Re: Administrator change users email without being logged in as user?

    06-26-2008, 7:51 AM
    • Member
      99 point Member
    • ClarkNK
    • Member since 05-24-2008, 11:56 PM
    • Upstate NY
    • Posts 202

    Masfenix, thank you for the reply I am trying your suggestion first. I'm a little new at working with the code behind, so here is what I tried (not quite working yet). 

    I am logged on with my username which gives me access to the admin page where I am trying to change user JohnDoe's email

    On that admin page I put a textbox with ID of "TxtBxNewEmail", a textbox with ID of  "UserName" , and a button with ID "BtnUpdateUserEmail"

    In the code behind page I put the following subroutine in the click event:

    ----------------------------------------------

    Dim user As MembershipUser

    user = Membership.GetUser(UserName)

    user.Email = TxtBxNewEmail.Text

    Membership.UpdateUser(user)

    ------------------------------------------------

    Then when viewing the admin page while logged on under my username, I type JohnDoe in the UserName text box, the JohnDoe's new email in the NewEmail text box and click on the button.

    I get the error: The provider user key supplied is invalid.  It must be of type System.Guid.
    Parameter name: providerUserKey

    I think It is very likely I implemented your suggestion incorrectly -- is that the problem? Or am I running into trouble because I am logged on as me and trying to change JohnDoe's profile?

    Thank you for your assistance.

    CHO, Homepage Doctor
    http://www.homepagedoctor.com/Tutorials.htm
  • Re: Administrator change users email without being logged in as user?

    06-26-2008, 8:14 AM
    • Member
      99 point Member
    • ClarkNK
    • Member since 05-24-2008, 11:56 PM
    • Upstate NY
    • Posts 202

    Got it working !!

     Satalaj, Masfenix thank you both.  I picked up from Satalaj code that I needed

    user = Membership.GetUser(GVProfilesAndUserName.SelectedValue)

    instead of what I had indicated in the previous post where I was trying Masfenix method.

    Thank you both.

     Teamwork !!

    CHO, Homepage Doctor
    http://www.homepagedoctor.com/Tutorials.htm
  • Re: Administrator change users email without being logged in as user?

    06-26-2008, 3:11 PM
    • Member
      473 point Member
    • masfenix
    • Member since 01-08-2007, 7:28 AM
    • Toronto
    • Posts 188

    Glad you got it working. However you were supposed to replace my "username" with your value!

    Note that Membership.GetUser() with get the current logged on user's information

    Visit http://www.dailytip.net to view your daily tip@!
  • Re: Administrator change users email without being logged in as user?

    06-26-2008, 4:55 PM
    • Member
      99 point Member
    • ClarkNK
    • Member since 05-24-2008, 11:56 PM
    • Upstate NY
    • Posts 202

    Yes, your solution was exactly right, thank you.  I was a little slow understanding it, but managed to put it together when poring over both posts.

    CHO, Homepage Doctor
    http://www.homepagedoctor.com/Tutorials.htm
Page 1 of 1 (7 items)