User-837620913 posted
A couple of issues. First, to set the property on anonymous users, you need to change your profile config to enable it, like this:
<system.web>
<anonymousIdentification enabled="true"/>
<trust level="Medium"/>
<profile >
<properties>
<add name="Name" allowAnonymous="true" />
<add name="Age" allowAnonymous="true" type="System.Int16"/>
</properties>
</profile>
<compilation debug="true"/>
</system.web>
Second, you can't set the profile in Page_Load. It has to be set in PreInit. You can add the following to global.asax:
protected void Application_PreRequestHandlerExecute(object sender, System.EventArgs e)
{
Page p = HttpContext.Current.Handler as Page;
if (p != null)
{
ProfileCommon pb = HttpContext.Current.Profile as ProfileCommon;
p.StyleSheetTheme = pb.Theme; // whatever theme is
}
}
For more details on these issues, see the answers in this thread: http://forums.asp.net/t/1225752.aspx/1/10?System+Configuration+Provider+ProviderException+This+property+cannot+be+set+for+anonymous+users