How to add a default value to a custom ASP.NET Profile property

Posted by mr.moses on Stack Overflow See other posts from Stack Overflow or by mr.moses
Published on 2010-06-16T14:15:48Z Indexed on 2010/06/16 14:32 UTC
Read the original article Hit count: 616

Filed under:
|
|
|
|

I know you can add defaultValues using the web.config like this:

<profile>
    <properties>
        <add name="AreCool" type="System.Boolean" defaultValue="False" />
    </properties>
</profile>

but I have the Profile inherited from a class:

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

Heres the class:

Public Class CustomProfile
    Inherits ProfileBase

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

End Class

I don't know how to set the default value of the property. Its causing errors because without a default value, it uses an empty string, which cannot be converted to a Boolean. I tried adding <DefaultSettingValue("False")> _ but that didn't seem to make a difference.

I'm also using a custom ProfileProvider (CustomProfileProvider).

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET