【发布时间】:2011-12-06 03:39:28
【问题描述】:
我有一个 Web 应用程序项目并在 web.config 中实现了配置文件属性。当我发现我无法访问 ProfileCommon 对象时,我用谷歌搜索并找到了一些解决方法:
- 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
等等。但是没有人说我在运行时有一个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) 的类型显示为ProfileCommon 而没有演员表。 Intellisense 不起作用,但可以检查对象,我看到它定义了两个配置文件属性。
如果这是除自定义 ProfileCommon 类之外的唯一方法,我不介意使用硬编码的配置文件属性名称,但我想解释一下为什么 ProfileCommon 类在运行时可用而不是编译时间?
【问题讨论】:
标签: c# asp.net-profiles compile-time