I look through the ASP.NET 4.0 online cource, just one of the first lessons.
I have Visual Studio 2012 for Web installed, and it has ASP.NET 4.5 on board.
In order to access some web.config properties, guy in the course writes following line:
Profile.Preferences.MyParameter = "MyValue";
but when I type the same thing, it gives me an error: Profile element doesn't exist in the current context
. And when I'm trying to access System.Web.Profile.Preferences
, it says that Type or namespace "Preferences" is missing in System.Web.Profile
.
Can anyone please tell what's happening? Is ASP.NET 4.5 the reason of this behavior, and if yes - how can I access the same web.config properties is ASP.NET 4.5?
My web.config looks like that:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<profile>
<properties>
<group name="Preferences">
<add name="MyParameter"/>
</group>
</properties>
</profile>
</system.web>
</configuration>
UPDATE: I've tried to implement the second solution from Joel Spolsky's answer: How to assign Profile values?
But the code doesn't work for me. The following method crahes:
static public AccountProfile CurrentUser
{
get { return (AccountProfile)
(ProfileBase.Create(Membership.GetUser().UserName)); }
}
It happens because Membership.GetUser() returns null. What Can I do with that?