我如何使用Profilebase类?
我尝试使用asp.net配置文件,我尝试使用ProfileBaseinheritance
public class dort_islem : ProfileBase { public int ilk_sayi { get; set; } public int ikinci_sayi { get; set; } }
但如果我尝试使用这些代码Default.aspx: alt text http://sofzh.miximages.com/c%23/zn5v60.gif
我如何从dort_islem类中看到ilk_sayi? 问候….
您缺少一些实现细节。
using System.Web.Profile; using System.Web.Security; namespace VideoShow { public class UserProfile : ProfileBase { public static UserProfile GetUserProfile(string username) { return Create(username) as UserProfile; } public static UserProfile GetUserProfile() { return Create(Membership.GetUser().UserName) as UserProfile; } [SettingsAllowAnonymous(false)] public string Description { get { return base["Description"] as string; } set { base["Description"] = value; } } [SettingsAllowAnonymous(false)] public string Location { get { return base["Location"] as string; } set { base["Location"] = value; } } [SettingsAllowAnonymous(false)] public string FavoriteMovie { get { return base["FavoriteMovie"] as string; } set { base["FavoriteMovie"] = value; } } } }
现在我们需要在web.config的配置文件部分中将其挂起 – 请注意我在配置文件声明中包含了inherits =“VideoShow.UserProfile”:
完成后,我可以获取自定义配置文件类的实例并设置属性:
//Write to a user profile from a textbox value UserProfile profile = UserProfile.GetUserProfile(currentUser.UserName); profile.FavoriteMovie = FavoriteMovie.Text; profile.Save();
来自http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx