I have a Web Application Project and implemented profile properties in the web.config. When I found that I couldn't access the ProfileCommon
object I googled and found some workarounds:
- How to Get List of User/Profile from Membership Provider?
- How to assign Profile values?
- "The name ProfileCommon does not exist in the current context"
- http://forums.asp.net/t/1487719.aspx/1?profile+common+non+existant+in+ASP+NET+4+0+
- http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx
And so on. But nobody said that I have a ProfileCommon
object at run-time. Here's my example:
<profile enabled="true">
<properties>
<add name="AdminRemark"/>
<add name="FacilityID" type="System.Int64" defaultValue="1"/>
</properties>
</profile>
This line compiles well and works, but I have the hard-coded property name:
rcbFacilityID.SelectedValue =
(ProfileBase.Create(userCurrent.UserName) as ProfileBase)
.GetPropertyValue("FacilityID").ToString();
But this line doesn't compile and gives the error: The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?)):
rcbFacilityID.SelectedValue =
(ProfileBase.Create(userCurrent.UserName) as ProfileCommon)
.FacilityID.ToString();
But at run-time I tried to execute the line in the Visual Studio Watch window and it worked! It event displayed the type of ProfileBase.Create(userCurrent.UserName)
as ProfileCommon
without the cast. Intellisense didn't work, but a could inspect the object and I saw that it had both profile properties defined.
I don't mind working with hard-coded profile property names if it's the only way except the custom ProfileCommon
class, but I'd like an explanation why the ProfileCommon
class is available at run-time and not a compile-time?