Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a very late post, but I just ran into this same problem when porting a VB.NET Visual Studio 2008 (.NET 3.5) website over to C# Visual Studio 2010 (.NET 4.0) website.</p> <p>I found references to <code>ProfileCommon</code> in MSDN's <a href="http://msdn.microsoft.com/en-us/library/system.web.profile.profilebase.aspx" rel="noreferrer">ProfileBase</a> documentation, but nothing on how to <strong>get</strong> that object.</p> <p>From your helpful MSDN link, I noticed that <code>ProfileCommon</code> would only ever be just a wrapper for the <code>HttpContext</code>.</p> <p>In short, I used the <code>var</code> keyword to extract the <code>ProfileCommon</code> information from the <code>HttpContext</code>, as in:</p> <pre><code>var profile = HttpContext.Current.Profile; </code></pre> <p>Using this one bit of information, I was able to create the entire class for reading and writing the information for my website visitors.</p> <p>Like you, I hope this code might help someone else:</p> <pre><code>using System.Web; using System.Web.Security; namespace WebApplication17 { public partial class ManageProfile : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (User.Identity.IsAuthenticated) { loadProfile(); } else { goHome(); } } } private void changePassword(string pwdOld, string pwdNew) { MembershipUser user = Membership.GetUser(User.Identity.Name); user.ChangePassword(pwdOld, pwdNew); Membership.UpdateUser(user); } private void goHome() { Server.Transfer("Default.aspx"); } private void loadProfile() { MembershipUser user = Membership.GetUser(User.Identity.Name); txtEmail.Text = user.Email; TextBox3.Text = user.GetPassword(); var profile = HttpContext.Current.Profile; txtTitle.Text = profile.GetPropertyValue("Title").ToString(); txtName.Text = profile.GetPropertyValue("Name").ToString(); txtAddress.Text = profile.GetPropertyValue("Address").ToString(); txtCity.Text = profile.GetPropertyValue("City").ToString(); txtSt.Text = profile.GetPropertyValue("St").ToString(); txtZip.Text = profile.GetPropertyValue("Zip").ToString(); txtPhone.Text = profile.GetPropertyValue("Phone").ToString(); txtFax.Text = profile.GetPropertyValue("Fax").ToString(); txtCompany.Text = profile.GetPropertyValue("Company").ToString(); } private void setProfile() { MembershipUser user = Membership.GetUser(User.Identity.Name); user.Email = txtEmail.Text; Membership.UpdateUser(user); var profile = HttpContext.Current.Profile; profile.SetPropertyValue("Title", txtTitle.Text); profile.SetPropertyValue("Name", txtName.Text); profile.SetPropertyValue("Address", txtAddress.Text); profile.SetPropertyValue("City", txtCity.Text); profile.SetPropertyValue("St", txtSt.Text); profile.SetPropertyValue("Zip", txtZip.Text); profile.SetPropertyValue("Phone", txtPhone.Text); profile.SetPropertyValue("Fax", txtFax.Text); profile.SetPropertyValue("Company", txtCompany.Text); profile.Save(); } protected void Button6_Click(object sender, EventArgs e) { changePassword(TextBox3.Text, TextBox4.Text); goHome(); } protected void Button11_Click(object sender, EventArgs e) { setProfile(); goHome(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload