+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / When are profile data present ?

When are profile data present ?

4 posts, 0 answered
  1. Daniel Svensson
    Daniel Svensson avatar
    12 posts
    Registered:
    31 Aug 2009
    08 Sep 2009
    Link to this post
    Hi,

    I have added an extra property DefaultLoginPage to profile section in web.config, and i can persist it to db through the CMS, as explained in the webinar for roles and membership on sitefinity.com.

    The question is, using the Login usercontrol in Sitefintiy/UserControls/ and listening to the LoggedIn event i want to
    then read that value of DefaultLoginPage. But the value isn't present, it is "". When are profile data present ?

    But im authenticated and logged in but im redirected to a page url of "" and get an error. Shouldn't profile data be read/writable upon authentication which already has happened before the LoggedIn event ?

    Code:

     void Page_Load(object sender, EventArgs e)
        {
            this.Login1.LoggedIn += new EventHandler(Login1_LoggedIn);
        }

        void Login1_LoggedIn(object sender, EventArgs e) {

            Response.Redirect(Profile.DefaultLoginPage);
        }

        
        public Login Login
        {
            get
            {
                return this.Login1;
            }
            set
            {
                this.Login1 = value;
            }
        }
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Sep 2009
    Link to this post
    Hi Daniel Svensson,

    Thank you for using our services.

    During the LoggedIn event of the Login Control the user is authenticated, however the session still does not have the current user. Your approach for redirecting in this event however is the correct one. You just have to modify the code a little bit to pull out the user profile by using the user name entered in the text box. Then you should use the ProfileBase.GetProperyValue method to get the value of the desired profile field:
     void Page_Load(object sender, EventArgs e) 
        { 
            this.Login1.LoggedIn += new EventHandler(Login1_LoggedIn);   
        } 
        void Login1_LoggedIn(object sender, EventArgs e) 
        { 
            //get the logged in user profile information 
            ProfileBase userProfile = ProfileBase.Create(Login1.UserName); 
            //if user login page is set redirect to it 
            if (userProfile.GetPropertyValue("DefaultLoginPage")!=null
                Response.Redirect(userProfile.GetPropertyValue("DefaultLoginPage"as string);    
        } 

    This should do the trick. If you have more questions, please feel free to contact us.

    Regards,
    Radoslav Georgiev
    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. Daniel Svensson
    Daniel Svensson avatar
    12 posts
    Registered:
    31 Aug 2009
    08 Sep 2009
    Link to this post
    Thanks! This did the trick! I was a bit confused, cause i thought that when you're authenticated the profiledata should be there :) But thanks for this code !

    /Daniel Svensson
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Sep 2009
    Link to this post
    Hi Daniel Svensson,

    I am glad I was able to help.

    I know it is a little bit confusing, but we are using three different providers - Membership Provider, to store user accounts and passwords, Role provider - to associate users to roles, and a Profile provider to store user profile information. So the easiest way to get profile date would be as in above post:
    //create an instance of user's profile 
    ProfileBase userProfile = ProfileBase.Create(string userName); 
     
    //to get profile data use 
    userProfile.GetPropertyValue(sting propertyName); 
     
    //to set profile data use 
    userProfile.SetPropertyValue(string propertyName, object propertyValue); 
     
    //to save changes made to user profile 
    userProfile.Save(); 

    We will be closing this thread now, if you need more information I think you already know how to reach us.

    Best wishes,
    Radoslav Georgiev
    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.
Register for webinar
4 posts, 0 answered