 |
|
|
|
Where is my Profile object?
|
|
|
 |
|
Location: Blogs Andy's Blog |
|
| Posted by: host |
8/1/2006 8:15 AM |
Profiles are supposed to be easy in ASP.NET 2.0. You just add a section in your web.config like so:
<profile defaultProvider="CustomizedProfileProvider">
<providers>
<add name="CustomizedProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MyConnectionString" applicationName="/MyApplicationName" />
< SPAN>providers>
<properties>
<add name="MySetting" type="int16" defaultValue="10" />
< SPAN>properties>
< SPAN>profile>
... after which ASP.NET 2.0 generates a nice strongly typed class for you so you can access your settings like so:
short x = Profile.MySetting;
Unfortunately, the strongly typed class is generated into your App_code folder. And if you have happened to use the VS2005 Web Application Projects Add-in, you won't have an App_code folder, which means you won't have access to the Profile strongly typed object.
There are two ways around this problem that I know of:
(1) there is another add-in called the WebProfile Generator just for these circumstances.
(2) if you can live with "loosely typed" Profile access, you can just code against a ProfileBase instance like so:
ProfileBase profile = ProfileBase.Create(Membership.GetUser().UserName);
short newSetting = 42;
profile.SetPropertyValue("MySetting", newSetting );
profile.Save();
|
|
| Permalink |
Trackback |
|
|
 |
|
 |
|
|