2010-03-26 76 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

相关问题