You could create an object and store that in the Profile.
For instance:
[Serializable]
public class ProfileObject { }
[Serializable]
class StudentProfile : ProfileObject
{
public string Year {get;set;}
public string Name {get;set;}
public string Age {get;set;}
}
[Serializable]
class TeacherProfile : ProfileObject
{
public string Department {get;set;}
public string Tenure {get;set;}
public string Rating {get;set;}
}
In web.config:
<profile>
...
<properties>
<add name="UserProfile" allowAnonymous="false" type="ProfileObject" serializeAs="Xml"/>
</properties>
</profile>
Edit: I can't remember if you can use an interface as the type or not. Changed it to object.
Access this via Profile.UserProfile (redundant, but it works).
Then, to process this, you'll have to check the type:
if(Profile.UserProfile is StudentProfile) { /* do something */ } else
if(Profile.UserProfile is TeacherProfile) { /* do something */ } // etc.
You could also store generics in the profile object (Perhaps Dictionary? The following is an implementation I've used)
For instance:
namespace Model
{
[Serializable]
public class RecentlyViewed : List<Model.Product>
{
public RecentlyViewed() {}
}
}
And in web.config:
<profile>
...
<properties>
<add name="RecentlyViewed" allowAnonymous="false" type="Model.RecentlyViewed" serializeAs="Xml"/>
</properties>
</profile>
I used this method in .NET 3.5, I'm not sure if it works in .NET 2 or 3. I would assume the generics are processed the same way, since the compiler hasn't changed.
Note:
It is necessary to inherit the generic object into an empty object, because the profile setting doesn't like the following:
<profile>
...
<properties>
<add name="RecentlyViewed" allowAnonymous="false" type="System.Collections.Generic.List`1[Model.Product]" serializeAs="Xml"/>
</properties>
</profile>
The above is the fully-qualified IL name as it really should look. The XML doesn't like the tick mark, it seems.
I haven't researched any performance issues with storing serialized objects in the Profile object, and therefore I wouldn't recommend this for any properties you'll need on a fairly regular basis.