2011-04-23 71 views
2

我正在使用asp.net會員資料。我可以創建配置文件並檢索值,但似乎無法設置屬性值。 我使用下面的代碼:asp.net會員資料更新

var profile = MemberProfile.GetUserProfile(); 
profile.fullName = tbFullName.Text; 
profile.country = tbCountry.Text; 
profile.city = tbCity.Text; 
profile.streetAddress = tbStreeAddress.Text; 
profile.phoneNumber = tbPhoneNumber.Text; 
profile.Save(); 

,這是不更新個人資料。 我也在網上查找了幾個解決方案,但似乎沒有任何工作。 配置文件類看起來是這樣的:

public class MemberProfile : ProfileBase 
{ 
    public static MemberProfile GetUserProfile(string username) 
    { 
     return (MemberProfile)Create(username); 
    } 

    public static MemberProfile GetUserProfile() 
    { 
     return (MemberProfile)Create(System.Web.Security.Membership.GetUser().UserName); 
    } 

    [SettingsAllowAnonymous(false)] 
    public string AuthGuid 
    { 
     get 
     { 
      var o = base.GetPropertyValue("auth_guid"); 
      if (o == DBNull.Value) 
      { 
       return string.Empty; 
      } 
      return (string)o; 
     } 
     set 
     { 
      base.SetPropertyValue("auth_guid", value); 
     } 
    } 

    [SettingsAllowAnonymous(false)] 
    public string fullName 
    { 
     get 
     { 
      var o = base.GetPropertyValue("fullName"); 
      if (o == DBNull.Value) 
      { 
       return string.Empty; 
      } 
      return (string)o; 
     } 
     set 
     { 
      base.SetPropertyValue("fullName", value); 
     } 
    } 

    [SettingsAllowAnonymous(false)] 
    public string country 
    { 
     get 
     { 
      var o = base.GetPropertyValue("country"); 
      if (o == DBNull.Value) 
      { 
       return string.Empty; 
      } 
      return (string)o; 
     } 
     set 
     { 
      base.SetPropertyValue("country", value); 
     } 
    } 

    [SettingsAllowAnonymous(false)] 
    public string city 
    { 
     get 
     { 
      var o = base.GetPropertyValue("city"); 
      if (o == DBNull.Value) 
      { 
       return string.Empty; 
      } 
      return (string)o; 
     } 
     set 
     { 
      base.SetPropertyValue("city", value); 
     } 
    } 

    [SettingsAllowAnonymous(false)] 
    public string streetAddress 
    { 
     get 
     { 
      var o = base.GetPropertyValue("streetAddress"); 
      if (o == DBNull.Value) 
      { 
       return string.Empty; 
      } 
      return (string)o; 
     } 
     set 
     { 
      base.SetPropertyValue("streetAddress", value); 
     } 
    } 

    [SettingsAllowAnonymous(false)] 
    public string phoneNumber 
    { 
     get 
     { 
      var o = base.GetPropertyValue("phoneNumber"); 
      if (o == DBNull.Value) 
      { 
       return string.Empty; 
      } 
      return (string)o; 
     } 
     set 
     { 
      base.SetPropertyValue("phoneNumber", value); 
     } 
    }   
} 

謝謝!

回答

1

您還需要在web.config中創造了性能

<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15"> 
     <providers> 
      <clear /> 
      <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" /> 
      <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" /> 
     </providers> 
     <properties> 
      <add name="auth_guid" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" /> 
      <add name="fullName" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" /> 
      <add name="country" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" /> 
      <add name="streetAddress" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" /> 
      <add name="phoneNumber" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" /> 
      <add name="city" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" /> 
     </properties> 
     </membership>