0

CMS の API と統合されたカスタム プロファイル プロバイダーを作成しました。認証されたユーザー ( ) のデータをプルするときは問題なく動作しますProfile.FirstNameが、新しいユーザーのプロファイルを作成するときにエラーが発生します。

ここに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.

4

1 に答える 1

0

問題が見つかりました。私は先週ずっと病気だったので、それが原因です。

GetPropertyValues関数でプロファイルを取得するとき、渡されたパラメーターのHttpContext.Current代わりにを使用していました。context

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
于 2010-02-16T23:22:44.090 に答える