2010-03-26 77 views
0

我試圖在代碼後面獲取配置文件屬性。但我沒有得到任何intellisence像Profile.HomephoneProfile.CellPhone。當我嘗試:未在代碼後面獲取配置文件屬性

Dim memberprofile As ProfileBase = HttpContext.Current.Profile 
Dim homePhone As String = memberprofile.GetPropertyValue("HomePhone").ToString() 

我得到​​。無法在Null值錯誤上調用此方法或屬性。我在配置文件表中有當前用戶的數據。 我得到以下結果在即時窗口

 
?HttpContext.Current.Profile.UserName.ToString 
"sub2" 
?Profile.DefaultProfile.Properties.Count 
2 
? HttpContext.Current.Profile("HomePhone") 
"" {String} 
    String: "" 

我不能夠在頁面加載事件運行的屬性值。 這是我的web.config文件設置:

<profile> 
    <providers> 
    <clear /> 
    <add name="AspNetSqlProfileProvider" connectionStringName="Primary" applicationName="MyFmNow.com" 
type="System.Web.Profile.SqlProfileProvider" /> 
    </providers> 
    <properties> 
    <add name="HomePhone" type="String" /> 
    <add name="CellPhone" type="String"/> 
    </properties> 
</profile> 
+0

This [weblog](http://weblogs.asp.net/anasghanem/archive/2008/04/12/the-differences-in-profile-between-web-application-projects-wap-and-website。 aspx)提供了有關此問題的一些有用信息。我面臨着完全相同的問題,但鏈接的網站幫助我獲得了不同。但我仍然在試圖找出原因。 – 2011-04-09 18:32:18

回答

0

,如果你調用toString(),如果數據爲空,你會得到一個錯誤;你可以這樣做:

Dim homePhone As String = CType(memberprofile.GetPropertyValue("HomePhone"), String) 

即使數據爲空,投射也可以正常工作。檢查後端數據庫;你是否在該用戶的aspnet_Profile(或類似名稱,不記得確切名稱)表中看到任何值?

HTH。

+0

數據不爲空。我有個人資料表中的家庭電話和手機值。這些是來自表格的2行。我仍然得到空。 用戶ID \t \t PropertyNames PropertyValuesString \t \t PropertyValuesBinary LastUpdatedDate 46B78D75-E1DB-494B-93CC-C87BE650A4B8 \t \t HOMEPHONE 7633954101 \t \t NULL 2010-03-23 19點16分51秒 46B78D75-E1DB-494B-93CC-C87BE650A4B8 \t手機 NULL \t 2010-03-23 19:16:51 – user228777 2010-03-26 12:34:58

+0

我假設用戶也登錄了...該guid與用戶的個人資料也是匹配的,因此請確保匹配。也許查詢發生得太快,你有哪些查詢代碼? – 2010-03-26 14:09:36

+0

我檢查過,用戶登錄後,它確實給我返回userName「sub2」。 – user228777 2010-03-26 15:15:36

相關問題