I tried creating a custom profile as described in several comments here and elsewhere, primarily so I could access my profile properties in class libraries. The code compiles properly, and the auto-generated ProfileCommon class reflects that I defined a custom profile. When I access a profile property my custom profile code is called, and my code calls GetPropertyValue(
propertyname) to return the property value. This somehow generates a call to my profile provider's GetPropertyValues method to get the values for ALL properties. That wouldn't normally be a problem, but profile group properties don't work! In normal operation (i.e. without my custom profile) my profile provider's GetPropertyValues method is called with a SettingsPropertyCollection containing entries for each defined property. Group properties are passed
groupName.
propertyName. But when my custom provider is implemented instead of including the group properties as
groupName.
propertyName they are included as JUST the group name, which causes an error to be thrown since that isn't a valid property. Has anyone else run into this problem and found a solution or workaround?
Here's my CustomProfile:
<serializable()>
Public Class WorkforceProfile
Inherits System.Web.Profile.ProfileBase
Public Overridable Property FirstName() As String
Get
Return CType(Me.GetPropertyValue("FirstName"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("FirstName", value)
End Set
End Property
Public Overridable Property LastName() As String
Get
Return CType(Me.GetPropertyValue("LastName"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("LastName", value)
End Set
End Property
Public Overridable Property Phone() As String
Get
Return CType(Me.GetPropertyValue("Phone"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("Phone", value)
End Set
End Property
Public Overridable Property Email() As String
Get
Return CType(Me.GetPropertyValue("Email"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("Email", value)
End Set
End Property
Public Overridable ReadOnly Property Company() As ProfileGroupCompany
Get
Return CType(Me.GetProfileGroup("Company"), ProfileGroupCompany)
End Get
End Property
Public Overridable ReadOnly Property Prefs() As ProfileGroupPrefs
Get
Return CType(Me.GetProfileGroup("Prefs"), ProfileGroupPrefs)
End Get
End Property
End Class
Public Class ProfileGroupCompany
Inherits System.Web.Profile.ProfileGroupBase
Public Overridable Property Name() As String
Get
Return CType(Me.GetPropertyValue("Name"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("Name", value)
End Set
End Property
Public Overridable Property LogoFile() As String
Get
Return CType(Me.GetPropertyValue("LogoFile"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("LogoFile", value)
End Set
End Property
Public Overridable Property DB() As String
Get
Return CType(Me.GetPropertyValue("DB"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("DB", value)
End Set
End Property
End Class
Public Class ProfileGroupPrefs
Inherits System.Web.Profile.ProfileGroupBase
Public Overridable Property LastResponseUsed() As String
Get
Return CType(Me.GetPropertyValue("LastResponseUsed"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("LastResponseUsed", value)
End Set
End Property
Public Overridable Property LastLocatorUsed() As String
Get
Return CType(Me.GetPropertyValue("LastLocatorUsed"), String)
End Get
Set(ByVal value As String)
Me.SetPropertyValue("LastLocatorUsed", value)
End Set
End Property
Public Overridable Property SideMenuCollapsed() As Boolean
Get
Return CType(Me.GetPropertyValue("SideMenuCollapsed"), Boolean)
End Get
Set(ByVal value As Boolean)
Me.SetPropertyValue("SideMenuCollapsed", value)
End Set
End Property
End Class