ProfileBaseを拡張するクラスを作成しました。
public class CustomerProfile : ProfileBase
{
public int CustomerID { get; set; }
public string CustomerName { get; set; }
public static CustomerProfile GetProfile()
{
return Create(Membership.GetUser().UserName) as CustomerProfile;
}
public static CustomerProfile GetProfile(string userName)
{
return Create(userName) as CustomerProfile;
}
}
私が行った場合:
CustomerProfile p = CustomerProfile.GetProfile();
p.CustomerID = 1;
p.Save();
次に現在のユーザーの値にアクセスしようとすると、1ではなく、0であるため、データベースに保存されていないようです。
私のweb.configファイルには、次のスニペットがあります。
<profile inherits="PortalBLL.CustomerProfile">
<providers>
<add name="CustomerProfile" type="System.Web.Profile.SqlProfileProvider" applicationName="/" connectionStringName="LocalSqlServer"/>
</providers>
</profile>
次のことを試しましたが、うまくいきました。自動プロパティを使用して保存されないのはなぜですか。
[SettingsAllowAnonymous(false)]
public int CustomerID
{
get { return (int)base.GetPropertyValue("CustomerID");}
set { base.SetPropertyValue("CustomerID",value);}
}