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

Forums / Developing with Sitefinity / Cannot read Profile due to exception

Cannot read Profile due to exception

3 posts, 0 answered
  1. Gilbert van Ooijen
    Gilbert van Ooijen avatar
    6 posts
    Registered:
    27 Aug 2009
    09 Sep 2009
    Link to this post
    I have extended the web.config with several custom user properties. In the forums I found code to read the user's profile:

    ProfileBase profile = ProfileBase.Create(user.UserName, true); 

    Now when I execute the code I get an exception on this line. The exception says:

    [System.Configuration.Provider.ProviderException] = {"Profile has not been enabled."}  
    InnerException = null 
    Message = "Profile has not been enabled." 

    I first thought my web.config was incorrect but I cannot find any errors here (see snippet below).
            <profile defaultProvider="Sitefinity">  
                <providers> 
                    <clear /> 
                    <add name="Sitefinity" connectionStringName="DefaultConnection" ApplicationName="/" 
                         type="Telerik.DataAccess.AspnetProviders.TelerikProfileProvider, Telerik.DataAccess" /> 
                </providers> 
                <properties> 
                    <add name="Common.FirstName" /> 
                    <add name="Common.Infix" /> 
                    <add name="Common.LastName" /> 
                    <add name="Common.IsDeleted" type="Bool" /> 
                    <add name="Common.IsHidden" type="Bool" /> 
                    <add name="Common.Gender" /> 
                    <add name="Common.PhotoId" /> 
                    <add name="Employee.Initials" /> 
                    <add name="Employee.AdditionalInfo" /> 
                    <add name="Employee.Birthdate" type="System.DateTime" /> 
                    <add name="Employee.Department" type="System.Guid" /> 

    There is one catch in my solution, I am building a migration tool and therefore I have a Console Application project in my Visual Studio solution. I bypassed the web.config by including all config settings in my app.config and also included all Telerik assemblies. This all works fine (I can create users for example) but now something's wrong. Can anyone help?
  2. Gilbert van Ooijen
    Gilbert van Ooijen avatar
    6 posts
    Registered:
    27 Aug 2009
    09 Sep 2009
    Link to this post
    Okay, it seems to be the dot '.' in the property names. With a dot in it I get this exception. I will now use underscores to prefix.

    For the record, I already tried to use Property Groups:

            <profile defaultProvider="Sitefinity">  
                <providers> 
                    <clear /> 
                    <add name="Sitefinity" connectionStringName="DefaultConnection" 
                         type="Telerik.DataAccess.AspnetProviders.TelerikProfileProvider, Telerik.DataAccess" /> 
                </providers> 
                <properties> 
                    <add name="FirstName" /> 
                    <add name="Infix" /> 
                    <add name="LastName" /> 
                    <add name="IsDeleted" type="Bool" /> 
                    <add name="IsHidden" type="Bool" /> 
                    <add name="Gender" /> 
                    <add name="Photo" defaultValue="~/Sitefinity/Common/Images/defaultavatar.gif" /> 
                    <group name="Employee">  
                        <add name="Initials" /> 
                        <add name="AdditionalInfo" /> 
                        <add name="Birthdate" type="System.DateTime" /> 
                        <add name="Department" type="System.Guid" /> 
                        <add name="EmployeeCode" /> 
     
    But this ended up in another unexpected error, a CompilationLock exception. Googling on this I found that it occors on more asp.net websites (http://forums.asp.net/p/1362855/2819920.aspx#2819920) without a real couse so I don't want to use this option.
  3. Joe
    Joe avatar
    138 posts
    Registered:
    24 Sep 2012
    09 Sep 2009
    Link to this post
    Hi Gilbert van Ooijen,

    Thanks for contacting us.

    I tried the following code and everything worked fine. Here was my Web.config:

                    <group name="Business"
                        <add name="FirstName"/> 
                        <add name="LastName"/> 
                    </group> 
     

    //Get the user name 
            MembershipUser user = Membership.GetUser(); 
            string UserName = user.UserName; 
            //Update the profile of the currently logged in user 
            ProfileBase profileBase = ProfileBase.Create(UserName, true); 
            profileBase.SetPropertyValue("Business.FirstName""Jack"); 
            profileBase.SetPropertyValue("Business.LastName""Jackson"); 
            string FirstName = profileBase.GetPropertyValue("Business.FirstName").ToString(); 
            string LastName = profileBase.GetPropertyValue("Business.LastName").ToString(); 
            //Save the profile  
            profileBase.Save(); 
            //Write the results 
            Response.Write(FirstName + " " + LastName); 

    Perhaps there is an issue with your current project? Please create a new one, then create a user control, upload it to the CMS with the code above. Does the error persist?

    Sincerely yours,
    Joe
    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
3 posts, 0 answered