我有一个 Web 应用程序项目并在 web.config 中实现了配置文件属性。当我发现我无法访问该ProfileCommon
对象时,我用谷歌搜索并找到了一些解决方法:
- 如何从会员提供者获取用户/个人资料列表?
- 如何分配配置文件值?
- “名称 ProfileCommon 在当前上下文中不存在”
- 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
等等。但是没有人说我ProfileCommon
在运行时有一个对象。这是我的例子:
<profile enabled="true">
<properties>
<add name="AdminRemark"/>
<add name="FacilityID" type="System.Int64" defaultValue="1"/>
</properties>
</profile>
此行编译良好且工作正常,但我有硬编码的属性名称:
rcbFacilityID.SelectedValue =
(ProfileBase.Create(userCurrent.UserName) as ProfileBase)
.GetPropertyValue("FacilityID").ToString();
但是这一行没有编译并给出错误:找不到类型或命名空间名称“ProfileCommon”(您是否缺少 using 指令或程序集引用?)):
rcbFacilityID.SelectedValue =
(ProfileBase.Create(userCurrent.UserName) as ProfileCommon)
.FacilityID.ToString();
但是在运行时,我尝试在 Visual Studio Watch 窗口中执行该行并且它起作用了!它事件显示了没有演员表的ProfileBase.Create(userCurrent.UserName)
as类型。ProfileCommon
Intellisense 不起作用,但可以检查对象,我看到它定义了两个配置文件属性。
如果这是除自定义类之外的唯一方法,我不介意使用硬编码的配置文件属性名称ProfileCommon
,但我想解释一下为什么ProfileCommon
该类在运行时可用而不是编译时可用?