How to assign Profile values?

前端 未结 10 796
别那么骄傲
别那么骄傲 2020-11-22 08:49

I don\'t know what I am missing, but I added Profile properties in the Web.config file but cannot access Profile.Item in the code or create a new profile.

10条回答
  •  生来不讨喜
    2020-11-22 08:57

    Profile can be used in Web Application Projects too. The properties can be defined in Web.config at design time or programmatically. In Web.config:

    
          
            
            
          
          
            
            
            
            
            
            
            
            
            
    
          
        
    

    or Programmatically, create the profile section by instantiating a ProfileSection and creating individual properties using ProfilePropertySettings and ProfilePropertySettingsColletion, all of which are in System.Web.Configuration Namespace. To use those properties of the profile, use System.Web.Profile.ProfileBase Objects. The profile properties cannot be accessed with profile. syntax as mentioned above, but can be easily done by instantiating a ProfileBase and using SetPropertyValue("PropertyName") and GetPropertyValue{"PropertyName") as follows:

    ProfileBase curProfile = ProfileBase.Create("MyName");
    

    or to access the profile of current user:

    ProfileBase curProfile = ProfileBase.Create(System.Web.Security.Membership.GetUser().UserName);
    
    
    
            curProfile.SetPropertyValue("FirstName", this.txtName.Text);
            curProfile.SetPropertyValue("LastName", this.txtLname.Text);
            curProfile.SetPropertyValue("Street", this.txtStreet.Text);
            curProfile.SetPropertyValue("Address2", this.txtAdd2.Text);
            curProfile.SetPropertyValue("ZIP", this.txtZip.Text);
            curProfile.SetPropertyValue("MobilePhone", txtMphone.Text);
            curProfile.SetPropertyValue("HomePhone", txtHphone.Text);
            curProfile.SetPropertyValue("DOB", txtDob.Text);
            curProfile.Save();
    

提交回复
热议问题