組み込みの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;
プロファイルクラスのコードは次のとおりです。
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;
}
}