0

I am using DOT NET 4 and VB.NET in a web application.

I have created all the SQL membership tables etc.. by using aspnet_regsql.exe

I can login, add user, delete users add roles etc...

Now I am trying to use the profile table to add some fields I need to be added to the newly created user upon registration.

in my web config I now have this

<profile defaultProvider="MyProfileProvider" >
            <providers>
                <clear />
                <add name="MyProfileProvider"
                     connectionStringName="DbConnString"
                     applicationName="/"
                     type="System.Web.Profile.SqlProfileProvider"/>
              </providers>
            <properties>
                <add name="OrganizationId" allowAnonymous="false" type="System.Int16" />
            </properties>
        </profile>

however I cannot figure out now how to use it. If from my code i try Profile.OrganizationId this is not part of the profile object.

if I try HttpContext.Current.Profile.SetPropertyValue("OrganizationId", OrgId) it works.

There is a simple way to access the Profile methods?

Also.. although I can see the property value in the aspnet_Profile table set to 115, when I try to get the value by HttpContext.Current.Profile.GetPropertyValue("OrganizationId") I get 0 as result ???

nobody has any idea on this ?

brillox
  • 363
  • 3
  • 22
  • possible duplicate of [How to assign Profile values?](http://stackoverflow.com/questions/426609/how-to-assign-profile-values) – William Smith Apr 13 '14 at 23:18
  • Hi William, maybe is a duplicate but also the other question does not solve my problem. I am able to save the property of my profile into the database, I can open the database table and see that I do have a row with my saved property value but when I try to retrieve the value I get 0 rather than 115 – brillox Apr 14 '14 at 07:24
  • I try to get the property as follow: HttpContext.Current.Profile.GetPropertyValue("OrganizationId") – brillox Apr 14 '14 at 07:24

1 Answers1

0

I found the issue(s)

  1. I was creating the property using HttpContext.Current.Profile.SetPropertyValue() which of course was ME logged in !! not the newly created user !! Dummy I am !!
  2. I was not calling the .Save() method after using the set propertyValue() method

So the final code is as follow:

WEB CONFIG

<profile defaultProvider="AspNetSqlProfileProvider" enabled="true" automaticSaveEnabled="true" >
<providers>
<clear />
<add name="AspNetSqlProfileProvider"
connectionStringName="DbConnString"
applicationName="MyApplication"
type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<add name="PropertyName" allowAnonymous="false" type="System.Int16" />
</properties>
</profile>

TO ASSIGN THE PROPERTY VALUE:

 Dim MyProfile As ProfileBase
    MyProfile = ProfileBase.Create(CreateUserWizard.UserName)
    PropertyValue =whatever you want
    MyProfile.SetPropertyValue("PropertyName", PropertyValue)
    MyProfile.Save()

TO GET THE PROPERTY VALUE

Dim MyProfile As ProfileBase
MyProfile = ProfileBase.Create(Membership.GetUser().UserName)
Myproeprty = MyProfile.GetPropertyValue("PropertyName")
brillox
  • 363
  • 3
  • 22