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

Forums / Developing with Sitefinity / Active Directory Profile Provider

Active Directory Profile Provider

6 posts, 0 answered
  1. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    05 May 2010
    Link to this post
    I'm trying to use Active Directory as my profile provider and can't seem to figure out how to implement it properly. This is my attempt at adding it to my web.config. Can you tell me where I'm going wrong and what I need to do to get this working? Thanks!

    <profile defaultProvider="Sitefinity">
      <providers>
        <clear />
        <add name="Sitefinity"
             connectionStringName="ADService"
             enableSearchMethods="true"
             attributeMapUsername="sAMAccountName"
             connectionUsername="username"
             connectionPassword="password"
             type="Telerik.Security.ActiveDirectory.TelerikADProfileProvider, Telerik.Security" />
      </providers>
    </profile>
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 May 2010
    Link to this post
    Hello Philip Senechal,

    There is no valid type TelerikADProfileProvider. The types that we support are for role and membership providers.
    • TelerikADMembershipProvider - Telerik membership provider for Active Directory uses ActiveDirectoryMembershipProvider
    • TelerikADRoleProvider - Telerik Role provider for Active Directory. The class uses Directory Services to query the domain through LDAP.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
  4. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    06 May 2010
    Link to this post
    I decided to go the route described here instead, but I seem to be getting an "Object reference not set to an instance of an object" error which is making me believe that I'm not populating the profile correctly. Can you maybe help me troubleshoot this method?

    I created a class file called InfoSourceProfile
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
     
    public class InfoSourceProfile : Telerik.DataAccess.AspnetProviders.TelerikProfileProvider
    {
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
        {
            SqlDataAdapter da = default(SqlDataAdapter);
            SqlConnection conn = new SqlConnection();
            SqlCommand cmd = default(SqlCommand);
            DataTable dt = new DataTable();
            SettingsPropertyValueCollection _settingsValues = new SettingsPropertyValueCollection();
            string userName = Convert.ToString(context["UserName"]);
     
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
     
            try
            {
                conn.Open();
                cmd = new SqlCommand("SELECT EmpID, Login FROM tUser WHERE Login = @UserName", conn);
     
                if (userName.Contains("VSPNT01\\"))
                {
                    userName = userName.Replace("VSPNT01\\", "");
                }
                cmd.Parameters.Add(new SqlParameter("@UserName", userName.ToLower()));
     
                da = new SqlDataAdapter(cmd);
                da.Fill(dt);
     
                foreach (SettingsProperty _property in properties)
                {
                    SettingsPropertyValue _settingsPropertyValue = new SettingsPropertyValue(_property);
                    if (dt.Rows.Count > 0)
                    {
                        switch (_property.Name)
                        {
                            case "EmpID": _settingsPropertyValue.PropertyValue = dt.Rows[0]["EmpID"];
                                break;
                            case "Login": _settingsPropertyValue.PropertyValue = dt.Rows[0]["Login"];
                                break;
                        }
                    }
     
                    _settingsValues.Add(_settingsPropertyValue);
                }
            }
     
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conn.Close();
            }
     
            return _settingsValues;
        }
    }

    this is pulling back 2 values from a table and I've made sure the SQL actually returns values. I even did away with the SQL and tried to hard code values into the properties just to get it to work.

    Here is the Profile section of my web.config

    <profile defaultProvider="InfoSourceProfile">
      <providers>
        <clear />
        <add name="Sitefinity" connectionStringName="DefaultConnection" applicationName="/" type="Telerik.DataAccess.AspnetProviders.TelerikProfileProvider, Telerik.DataAccess" />
        <add name="InfoSourceProfile" connectionStringName="DefaultConnection" type="InfoSourceProfile" />
      </providers>
      <properties>
        <add name="FirstName" />
        <add name="LastName" />
        <add name="EmpID" provider="InfoSourceProfile" />
        <add name="Login" provider="InfoSourceProfile" />
      </properties>
    </profile>

    I'm just trying to populate the Text of a label with Profile.EmpID or Profile.Login when I get the error. It makes me think that I'm not assigning values to the profile properties correctly.

    Any assistance you can provide is greatly appreciated. Thanks.
  5. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    10 May 2010
    Link to this post
    Wow...total rookie move and I figured it out. I was using the wrong connection string. "DefaultConnection" refers to the Telerik data provider connecting to the Sitefinity database and I just needed a basic SQL provider...so changing the connection string to point to "Sitefinity" instead made the whole thing work perfectly.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 May 2010
    Link to this post
    Hello Philip Senechal,

    You could override Initialize to set the connectionString directly from the configuration

    public override void Initialize(string name, NameValueCollection config)      
       {
                string connectionStringName = config["ADConnectionString"];
                config.Remove("ADConnectionString");
                SetConnectionString(connectionStringName );
     
                SetCredentials(config);
                config.Remove("connectionUsername");
                config.Remove("connectionPassword");
                base.Initialize(name, config);
     }
     
     
           
            public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
            {
                SettingsPropertyValueCollection spv = new SettingsPropertyValueCollection();
                if (properties.Count < 1)
                    return spv;
     
                string username = (string)context["UserName"];
                foreach (SettingsProperty prop in properties)
                {
                    if (prop.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                        if (prop.PropertyType.IsPrimitive || prop.PropertyType == typeof(string))
                            prop.SerializeAs = SettingsSerializeAs.String;
                        else
                            prop.SerializeAs = SettingsSerializeAs.Xml;
                    spv.Add(new SettingsPropertyValue(prop));
                }
     
                if (!String.IsNullOrEmpty(username))
                {
                    Guid userId = this.GetGuidByUsername(username);
     
                    Profile profile = new Profile(userId);
                           // here you need to make some database transtaction.
                    if (profile != null)
                    {
                                                                
                        for (int i = 0; i < profile.MetaData.Count; i++)
                        {
                            UserMetaInfo meta = profile.MetaData_static[i];
     
                            SettingsPropertyValue pp = svc[meta.PropertyName];
                            if (pp == null)
                                continue;
     
                            pp.PropertyValue = meta.Value;
                        }
                    }
                }
                return spv;
            }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
6 posts, 0 answered