Not Getting Profile properties in Code Behind
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 we开发者_运维百科b.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>
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.
精彩评论