未在代码隐藏中获取配置文件属性

发布于 2024-08-26 20:46:47 字数 1017 浏览 5 评论 0原文

我正在尝试在后面的代码中获取配置文件属性。但我没有得到任何像 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>

I am trying to get Profile properties in the code behind. But I am not getting any intellisence like Profile.Homephone or Profile.CellPhone. When I try:

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

I get Data is Null. This method or property cannot be called on Null values error. I have data for current user in the profile Table.
I get following results in immediate window

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

I am not able to run property values in page load event.
This is my web.config file setting:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2024-09-02 20:46:47

如果 data 为 null,则调用 ToString() 会出现错误;您可以通过执行以下操作来解决此问题:

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

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

HTH。

You will get an error if you call ToString() if data is null; you can work around that by doing:

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

Casting will work OK even if the data is null. Check the backend database; do you see any values in the aspnet_Profile (or similarly named, can't remember exact name) table for that user?

HTH.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文