未在代码隐藏中获取配置文件属性
我正在尝试在后面的代码中获取配置文件属性。但我没有得到任何像 Profile.Homephone
或 Profile.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 data 为 null,则调用 ToString() 会出现错误;您可以通过执行以下操作来解决此问题:
即使数据为空,强制转换也可以正常工作。检查后台数据库;您是否在 aspnet_Profile (或类似名称,记不清确切名称)表中看到该用户的任何值?
HTH。
You will get an error if you call ToString() if data is null; you can work around that by doing:
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.