我有一个Web应用程序项目并在web.config中实现了配置文件属性。当我发现我无法访问ProfileCommon
对象我用Google搜索,发现了一些解决方法: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监视窗口中执行的行,它成功了!该事件显示ProfileBase.Create(userCurrent.UserName)
的类型为ProfileCommon
而没有演员。智能感知不起作用,但可以检查该对象,并且我看到它具有定义的两个配置文件属性。
我不介意使用硬编码的配置文件属性名称,如果它是唯一的方式,除了自定义ProfileCommon
类,但我想解释为什么ProfileCommon
类在运行时可用而不是编译 - 时间?
这是一个奇怪的行为,但是当我通过实现我的自定义类“KIP_Profile:ProfileBase”修复该问题时,出现错误“此配置文件属性已被定义。”当试图运行语句'创建(userCurrent.UserName)' – Mentoliptus
如果您已经在类和web.config配置文件部分中定义了相同的属性,就会发生这种情况。 – loodakrawa
谢谢!从'web.config'文件中删除属性定义并在'KIP_Profile'中移动它们解决了这个问题! – Mentoliptus