More in this section

Forums / Developing with Sitefinity / Capture telerik_Users "Email" for Label

Capture telerik_Users "Email" for Label

9 posts, 0 answered
  1. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    11 Nov 2009
    Link to this post
    I would like to capture the user who is logged in e-mail address for my app.  How can i do this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Nov 2009
    Link to this post
    Hello medicalwebgeek,

    You can subscribe for Login1_Authenticate event of Login control and send an email that contains data for the currently logged in user. You can use MembershipUser class if you need to extract any additional data.

    here is a sample code:

    protected void Page_Load(object sender, EventArgs e)
        {
     
    this.Login1.LoggedIn += new EventHandler(Login1_LoggedIn);
            this.Login1.Authenticate += new AuthenticateEventHandler(Login1_Authenticate);
        }
     
        void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            e.Authenticated = UserManager.Default.ValidateUser(this.Login1.UserName, this.Login1.Password);
            if (e.Authenticated)
            {
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(sender, receivedby);
                message.Body = "User:" + this.Login1.UserName + "logged in";
                SmtpClient client = new SmtpClient();
                client.Send(message);
     
            }
        }



    Note that this may slow the login process due to the sending of email address.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    12 Nov 2009
    Link to this post
    Thanks for the help.  I am trying to capture the users e-mail address from their profile and write that to a label just like I am for the FirstName + LastName.  I can see the Username, but I cannot find out how to get their e-mail address.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Nov 2009
    Link to this post
    Hello medicalwebgeek,

    Then try the code below:

    MembershipUser user = Membership.GetUser("currentuser");
    string uEmail = user.Email;


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    13 Nov 2009
    Link to this post
    I inserted this into my pageload and when i debug the code I get a uEmail = null.  Any suggestions?

    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Nov 2009
    Link to this post
    Hello medicalwebgeek,

    If it is null this means that there is no email for the user you use. Try debugging the code and after the break point for the user is hit run the immediate window and type user.Email to see the value. More information at MSDN.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    13 Nov 2009
    Link to this post
    The users are the same one that are in the table telerik_Users.  They all have to have e-mail addresses and I have ferfied that they do.

    Any suggestions?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Nov 2009
    Link to this post
    Hello medicalwebgeek,

    Since you are working with the membership data, it is not possible to get null value.

    Try the following code which uses the same method and classes:

    MembershipUserCollection collection = Membership.GetAllUsers();
           foreach (MembershipUser user in collection)
           {
               Response.Write(user.Email + "-" + user.UserName + "<br />");
           }

    Also go through the articles that I sent you, since this is general ASP.NET

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    13 Nov 2009
    Link to this post
    I was able to get it to work by removing "currentuser" from:


     MembershipUser user = Membership.GetUser("currentuser");
            string uEmail = user.Email;

            if ((uEmail != null) && (uEmail != ""))
                lblEmail.Text = uEmail;

Register for webinar
9 posts, 0 answered