views:

143

answers:

1

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.

A: 

Hey,

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.

Brian
Data is not null. I have home phone and cell phone values in profile table. These are 2 rows from a table. And still I get null. UserId PropertyNames PropertyValuesString PropertyValuesBinary LastUpdatedDate46B78D75-E1DB-494B-93CC-C87BE650A4B8 HomePhone 7633954101 NULL 2010-03-23 19:16:5146B78D75-E1DB-494B-93CC-C87BE650A4B8 CellPhone 3134548795 NULL 2010-03-23 19:16:51
I assume the user is logged in too... The guid matches the user who the profile is for also, so ensure that matches up. Maybe the query is happening too soon, where do you have the code that queries it in?
Brian
I checked, user is logged in an it does give me back userName "sub2".
When I do ?HttpContext.Current.Profile.UserName.ToString it gives the name "sub2" but when I type ?profile. I don't get property HomePhone and CellPhone in immidiate window.
I've had issues with profile strong typing, and you don't get intellisense outside of the code-behind file, so that isn't an indication of the setup... though what does your config file setup look like too... I don't see it in the original post...
Brian
This is my web.config for provider. <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>