locked
Profile properties RRS feed

  • Question

  • User791773689 posted

    Hello everybody,

    I wrote a custom ProfileProvider, with which I could write a property with

    ? Context.Profile.SetPropertyValue("ZipCode", "54400")

    and read it with

    ? Context.Profile.GetPropertyValue("ZipCode")

    and it is permanent over sessions, but I am supposed to be able to access to it with

    Context.Profile.ZipCode

    and Profile has no ZipCode property.

    I presume I missed something while writing the profile provider.

    Any idea what ?

    Friday, September 28, 2018 3:00 PM

Answers

  • User1724605321 posted

    Hi Gluups ,

    If you are in web application , you cannot use Profile.item directly... the strongly-typed class is not magically generated for you from the Web.config file, so you have to roll your own. You have two choice : 

    1.Use the Web Profile Builder. This is a custom tool you add to Visual Studio which automatically generates the Profile object you need from your definition in Web.config.

    2.Make your own class that derives from ProfileBase to represent your custom profile like your codes .

    You can refer to below code sample for explanation and detail code sample :

    https://stackoverflow.com/questions/426609/how-to-assign-profile-values 

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 1, 2018 2:01 AM

All replies

  • User1724605321 posted

    Hi Gluups ,

    If you are in web application , you cannot use Profile.item directly... the strongly-typed class is not magically generated for you from the Web.config file, so you have to roll your own. You have two choice : 

    1.Use the Web Profile Builder. This is a custom tool you add to Visual Studio which automatically generates the Profile object you need from your definition in Web.config.

    2.Make your own class that derives from ProfileBase to represent your custom profile like your codes .

    You can refer to below code sample for explanation and detail code sample :

    https://stackoverflow.com/questions/426609/how-to-assign-profile-values 

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 1, 2018 2:01 AM
  • User791773689 posted

    Hello,

    Well I wrote a ProfileProvider, thank you. I must have missed something in it.

    After that, some work remains to be done, as the example that I translated was based on a particular case, of a profile that contains a ZipCode and a stock object, and, curiously enough, creates a field per property in the ProfileData table.

    So, I work on the webParts, and when I am done with it I shall come back to the profile provider and make it able to manage different properties given in the Web.config -and manage the exceptions.

    Some documentation will be needed also I presume.

    Well for the time being, I have got the contents of the existing properties, but with a heavy syntax. The question was how to get the zipcode with Profile.ZipCode

    Monday, October 1, 2018 8:28 AM
  • User791773689 posted

    In fact yes, you gave me the answer, in Stackoverflow's page :

    dynamic profile = System.Web.Profile.ProfileBase.Create(Context.User.Identity.Name);
    string s = profile.ZipCode;
    

    Dynamic profile was the key, and as you see I adapted the syntax for getting the user's name to initiate the profile.

    Well, thank you very much.

    I put that somewhere in the master page, maybe there is a better place to put that, for instance just after the login ?

    Monday, October 1, 2018 9:01 AM