[英]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.