[英]ProfileCommon in WAP working at run-time but not at compile-time
我有一个Web应用程序项目并在web.config中实现了配置文件属性。 当我发现我无法访问ProfileCommon
对象时,我用Google搜索并找到了一些解决方法:
等等。 但没有人说我在运行时有一个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
而不铸造。 智能感知不起作用,但是可以检查对象,我看到它定义了两个配置文件属性。
我不介意使用硬编码的配置文件属性名称,如果除了自定义的ProfileCommon
类之外它是唯一的方法,但我想解释为什么ProfileCommon
类在运行时而不是编译时可用?
ProfileCommon在编译时不可用,因为它是在启动应用程序时创建的类。 这是由于您可以在web.config中的profile元素内定义的属性,因此可以动态添加它们。 请参阅官方文档中的备注。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.