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

Forums / Developing with Sitefinity / Adding Extra Properties with ActiveDirectory Membership Provider

Adding Extra Properties with ActiveDirectory Membership Provider

6 posts, 0 answered
  1. MNP
    MNP avatar
    79 posts
    Registered:
    23 Apr 2008
    23 Jul 2009
    Link to this post
    I thought I would post this here as I'm sure it will be beneficial to others.

    We use the TelerikADMembership provider to hook up to AD to give access to the users, however AD keeps limited information about the user, so I wanted to bring back more information - Personnel Number, Picture, Classification, etc from our HR system.

    To do this, you must create a ProfileProvider - I simply inherited from Telerik's Profile Provider and override the GetPropertyValues() function
       Public Class MNPProfiles 
          Inherits Telerik.DataAccess.AspnetProviders.TelerikProfileProvider 
     
     Public Overrides Function GetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal properties As System.Configuration.SettingsPropertyCollection) As System.Configuration.SettingsPropertyValueCollection 
     
             Dim da As SqlDataAdapter 
             Dim conn As New SqlConnection 
             Dim cmd As SqlCommand 
             Dim dt As New Data.DataTable 
             Dim _settingsValues As SettingsPropertyValueCollection = New SettingsPropertyValueCollection() 
             Dim userName As String = CType(context("UserName"), String
     
             conn.ConnectionString = mConnectionString 
     
             Try 
     
                conn.Open() 
                cmd = New SqlCommand("WS_LookupUser", conn) 
                cmd.CommandType = Data.CommandType.StoredProcedure 
     
                cmd.Parameters.Add(New SqlParameter("@PersNo", 0)) 
     
                If userName.Contains("MNP\"Then 
                   userName = Replace(userName, "MNP\"""
                End If 
                cmd.Parameters.Add(New SqlParameter("@UserName", LCase(userName))) 
     
     
                da = New SqlDataAdapter(cmd) 
                da.Fill(dt) 
     
                For Each _property As SettingsProperty In properties 
                   Dim _settingsPropertyValue As SettingsPropertyValue = New SettingsPropertyValue(_property) 
     
                   If dt.Rows.Count > 0 Then 
                      Select Case _property.Name 
                         Case "PersonnelNo" 
                            _settingsPropertyValue.PropertyValue = dt.Rows(0).Item("Personnel_No"
                      End Select 
                   End If 
     
                   _settingsValues.Add(_settingsPropertyValue) 
                Next 
             Catch ex As Exception 
                Throw New Exception(ex.Message) 
             Finally 
                conn.Close() 
             End Try 
     
             Return _settingsValues 
     
          End Function 
     


    Inside your web.config fill in your new properties as well as your new ProfileProvider:

    <profile defaultProvider="MNPProfiles"
                <providers> 
                    <clear/> 
                    <add name="Sitefinity" connectionStringName="DefaultConnection" applicationName="/" type="Telerik.DataAccess.AspnetProviders.TelerikProfileProvider, Telerik.DataAccess"/> 
                <add name="MNPProfiles" connectionStringName="DefaultConnection" type="MNP.Web.Providers.MNPProfiles, MNP.Web"/> 
                </providers> 
                <properties> 
                    <add name="FirstName"/> 
                    <add name="LastName"/> 
                <add name="PersonnelNo" provider="MNPProfiles" type="System.Int32"/> 
                 
                </properties> 
            </profile> 

    Then for example, inside a user profile page on your website, simply grab that property

         If Not Profile.IsAnonymous Then 
             lblTitle.Text = mTitle 
          Else 
             lblTitle.Text = Profile.PersonnelNo & " - " & mTitle 
          End If 
     

    It's that simple.


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Jul 2009
    Link to this post
    Hi Matt,

    Thank you for sharing your code with us. We update your Telerik points.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Muhammad Saqib
    Muhammad Saqib avatar
    95 posts
    Registered:
    09 Sep 2009
    09 Nov 2009
    Link to this post
    WS_LookupUser not found.....what to do?
  4. MNP
    MNP avatar
    79 posts
    Registered:
    23 Apr 2008
    09 Nov 2009
    Link to this post
    Hi Muhammad,

    WS_LookupUser is just a stored procedure call that brings back the information needed to populate the settings (Personnel_No, Classification, Office, etc). In this situation I use a separate database, but this data can really come from anywhere, not necessarily SQL.

    -<att
  5. Muhammad Saqib
    Muhammad Saqib avatar
    95 posts
    Registered:
    09 Sep 2009
    09 Nov 2009
    Link to this post
    Do you have the complete code for this implementation. Please i need it urgent.
    The problem i have that I authenticate user from Active Directory and there is also Profile Properties which i need to maintian over the site. but it does'nt allowing me to do so... :-(

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Nov 2009
    Link to this post
    Hi Muhammad Saqib,

    Generally Sitefinity is only acceptor for AD users. The users that comes from AD cannot be edited, deleted, created through Sitefinity. You can consider migrating AD users to Sitefinity membership and profile provider.

    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.
Register for webinar
6 posts, 0 answered