0

我正在尝试在后面的代码中获取 Profile 属性。但我没有得到任何类似Profile.Homephoneor的情报Profile.CellPhone。当我尝试:

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

我明白了Data is Null。无法在 Null 值错误时调用此方法或属性。我在配置文件表中有当前用户的数据。我在即时窗口中得到以下结果

?HttpContext.Current.Profile.UserName.ToString
“子2”
?Profile.DefaultProfile.Properties.Count
2
? HttpContext.Current.Profile("HomePhone")
““ {细绳}
    细绳: ””

我无法在页面加载事件中运行属性值。这是我的 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>
4

1 回答 1

0

如果 data 为 null,则调用 ToString() 会出错;您可以通过以下方式解决此问题:

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

即使数据为空,转换也可以正常工作。检查后端数据库;您在 aspnet_Profile (或类似名称,不记得确切名称)表中看到该用户的任何值吗?

HTH。

于 2010-03-26T12:25:35.373 回答