2010-02-11 97 views
0

我創建了與CMS的API集成的自定義配置文件提供程序。在爲已認證的用戶(Profile.FirstName)提取數據時它工作正常,但在創建新用戶配置文件時出錯。使用CMS API的自定義配置文件提供程序

這裏是web.config中

<profile enabled="true" defaultProvider="CustomProfileProvider" inherits="objProfile"> 
    <providers> 
    <clear /> 
    <add name="CustomProfileProvider" type="CustomProfileProvider" /> 
    </providers> 
</profile> 

部分下面是objProfile類

Public Class objProfile 
    Inherits ProfileBase 

    Public Property FirstName() As String 
     Get 
      Return Me.GetPropertyValue("FirstName") 
     End Get 
     Set(ByVal value As String) 
      Me.SetPropertyValue("FirstName", value) 
     End Set 
    End Property 

    Public Property LastName() As String 
     Get 
      Return Me.GetPropertyValue("LastName") 
     End Get 
     Set(ByVal value As String) 
      Me.SetPropertyValue("LastName", value) 
     End Set 
    End Property 

    Public Property Email() As String 
     Get 
      Return Me.GetPropertyValue("Email") 
     End Get 
     Set(ByVal value As String) 
      Me.SetPropertyValue("Email", value) 
     End Set 
    End Property 

    Public Property Address1() As String 
     Get 
      Return Me.GetPropertyValue("Address1") 
     End Get 
     Set(ByVal value As String) 
      Me.SetPropertyValue("Address1", value) 
     End Set 
    End Property 

    ... 

    Public Property MailList() As Boolean 
     Get 
      Return Me.GetPropertyValue("Mailing List") 
     End Get 
     Set(ByVal value As Boolean) 
      Me.SetPropertyValue("Mailing List", value) 
     End Set 
    End Property 

End Class 

這裏是習俗ProfileProvider。現在唯一實現的功能是GetPropertyValues,因爲這是調試器逐步完成時唯一使用的功能。我會根據需要實施其他人。

Public Class CustomProfileProvider 
    Inherits ProfileProvider 

    Public Overrides Property ApplicationName() As String 
     Get 
      Return ConfigurationManager.AppSettings("ApplicationName") 
     End Get 
     Set(ByVal value As String) 
      Return 
     End Set 
    End Property 

    Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection) 
     MyBase.Initialize(name, config) 
    End Sub 

    Public Overrides Function DeleteInactiveProfiles(ByVal authenticationOption As System.Web.Profile.ProfileAuthenticationOption, ByVal userInactiveSinceDate As Date) As Integer 

    End Function 

    Public Overloads Overrides Function DeleteProfiles(ByVal usernames() As String) As Integer 

    End Function 

    Public Overloads Overrides Function DeleteProfiles(ByVal profiles As System.Web.Profile.ProfileInfoCollection) As Integer 

    End Function 

    Public Overrides Function FindInactiveProfilesByUserName(ByVal authenticationOption As System.Web.Profile.ProfileAuthenticationOption, ByVal usernameToMatch As String, ByVal userInactiveSinceDate As Date, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Profile.ProfileInfoCollection 

    End Function 

    Public Overrides Function FindProfilesByUserName(ByVal authenticationOption As System.Web.Profile.ProfileAuthenticationOption, ByVal usernameToMatch As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Profile.ProfileInfoCollection 

    End Function 

    Public Overrides Function GetAllInactiveProfiles(ByVal authenticationOption As System.Web.Profile.ProfileAuthenticationOption, ByVal userInactiveSinceDate As Date, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Profile.ProfileInfoCollection 

    End Function 

    Public Overrides Function GetAllProfiles(ByVal authenticationOption As System.Web.Profile.ProfileAuthenticationOption, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Profile.ProfileInfoCollection 

    End Function 

    Public Overrides Function GetNumberOfInactiveProfiles(ByVal authenticationOption As System.Web.Profile.ProfileAuthenticationOption, ByVal userInactiveSinceDate As Date) As Integer 

    End Function 

    Public Overrides Function GetPropertyValues(ByVal cotext As System.Configuration.SettingsContext, ByVal collection As System.Configuration.SettingsPropertyCollection) As System.Configuration.SettingsPropertyValueCollection 
     Dim PropertyValueCollection As New System.Configuration.SettingsPropertyValueCollection 
     ... (get user properties from cms and put into PropertyValueCollection) ... 
     'return the PropertyValueCollection 
     Return PropertyValueCollection 
    End Function 

    Public Overrides Sub SetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal collection As System.Configuration.SettingsPropertyValueCollection) 

    End Sub 

End Class 

在登錄的用戶頁面上,Profile.FirstName工作正常。但是當我創建一個新用戶,然後使用objProfile.Create(UserName)來創建配置文件時,所有屬性都有一個錯誤,如The settings property 'Mailing List' was not found.

+0

哪個CMS400的版本您使用的? (我假設來自Ektron標籤的CMS400)。 – 2010-02-11 20:36:42

+0

最新版本,v8。使用API​​沒有問題,我只是無法將它與.NET ProfileProvider集成。 – 2010-02-12 14:21:25

回答

0

我發現了這個問題。我上週生病了,所以我就責怪那個。

GetPropertyValues功能越來越輪廓,我使用的是傳入的,而不是HttpContext.Currentcontext參數。

Public Overrides Function GetPropertyValues(ByVal context As System.Configuration.SettingsContext, ByVal collection As System.Configuration.SettingsPropertyCollection) As System.Configuration.SettingsPropertyValueCollection 
    Dim PropertyValueCollection As New System.Configuration.SettingsPropertyValueCollection 

    'get username from parameter, context.Item("UserName"), not HttpContext.Current.User.Identity.Name.ToString() 

    ...get user properties from CMS and put into PropertyValueCollection... 

    'return the PropertyValueCollection 
    Return PropertyValueCollection 
End Function 
相關問題