我按照在线教程使用内置的 asp.net 分析器,但没有获取配置文件。每次运行 GetUserProfile 时它都返回 null:
这是我的调用代码:
if (UserProfile.GetUserProfile() == null)
{
UserProfile.Create(Membership.GetUser().UserName);
}
UserProfile currentProfile = UserProfile.GetUserProfile();
currentProfile.WorksAt = "WorksAt Test";
currentProfile.Manages = "Manages Test";
String WorksAt = currentProfile.WorksAt;
String Manages = currentProfile.Manages;
这是我的 Profile 类的代码:
using System.Web.Profile;
using System.Web.Security;
public class UserProfile : ProfileBase
{
[SettingsAllowAnonymous(false)]
public string WorksAt
{
get { return base["WorksAt"] as string; }
set { base["WorksAt"] = value; }
}
[SettingsAllowAnonymous(false)]
public string Manages
{
get { return base["Manages"] as string; }
set { base["Manages"] = value; }
}
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as UserProfile;
}
}