asp.net 2.0 Profiles for custom type

R

Rajesh

I am trying to use a simple custom type for saving the profile
information of a user. The custom class inherits from the Hashtable. I
am serializing the type as "Binary" in the provider sections of the
web.config.

When I add a key-value to the custom type, I can see that its being
saved in the database (aspnet_profiles table - PropertyValuesBinary
column). But, when I want to read the information in the profile, my
custom type object is not being initialized. There are no items in it.

The exact same code works if I specify the type as
"System.Collections.Hashtable" instead of my custom type in the
web.config (line commented in the web.config below).

I could not figure out, what is the problem. Do we have to do something
different to serialize the custom types?

Any help would be greatly appreciated!

Thanks,
Raj

This is the code snippet:

Web.Config
****************************************************************************************************
<profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
<providers>
<remove name="AspNetSqlProfileProvider"/>
<add name="AspNetSqlProfileProvider"
connectionStringName="LocalSqlServer"
applicationName="SEM"
type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<!--add name="htVal" type="System.Collections.Hashtable"
serializeAs="Binary"/-->
<add name="htVal" type="TestProfiles.Custom"
serializeAs="Binary"/>
</properties>
</profile>


Custom.cs
*****************************************************************************************************
namespace TestProfiles
{
[Serializable]
public class Custom: System.Collections.Hashtable
{

}
}


Usage in a TestProfile.aspx.cs
*****************************************************************************************************
public void SaveProfile()
{
this.Profile.htVal.Add("XXX", "YYY");
}

public void ShowProfile()
{
//lblMsg.Text value is 0, when I use custom type and 1 when I use
Hashtable type in web.config
lblMsg.Text = this.Profile.htVal.Count.ToString();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Profiles 0
Profiles 1
Profiles & Membership 0
Profiles 0
Current user profile 0
Profiles problem 0
Profiles - extend property attributes? 0
Profiles in Asp.net 2

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top