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();
}
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();
}