0

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>
MPelletier
  • 16,256
  • 15
  • 86
  • 137
user228777
  • 3,082
  • 9
  • 33
  • 50
  • This [weblog](http://weblogs.asp.net/anasghanem/archive/2008/04/12/the-differences-in-profile-between-web-application-projects-wap-and-website.aspx) provides some useful information about this issue. I was facing the exact same issue, but the linked site helped me get the difference. But I'm still trying to find out the reason for this. – Roshan Kumar Singh Apr 09 '11 at 18:32

1 Answers1

0

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 Mains
  • 50,520
  • 35
  • 148
  • 257
  • 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 LastUpdatedDate 46B78D75-E1DB-494B-93CC-C87BE650A4B8 HomePhone 7633954101 NULL 2010-03-23 19:16:51 46B78D75-E1DB-494B-93CC-C87BE650A4B8 CellPhone 3134548795 NULL 2010-03-23 19:16:51 – user228777 Mar 26 '10 at 12:34
  • 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 Mains Mar 26 '10 at 14:09
  • I checked, user is logged in an it does give me back userName "sub2". – user228777 Mar 26 '10 at 15:15
  • 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. – user228777 Mar 26 '10 at 15:18
  • 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 Mains Mar 26 '10 at 17:32
  • This is my web.config for provider. – user228777 Mar 26 '10 at 19:12