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);
}
}
}
谢谢!
I'm working with asp.net member profiles. I can create the profile and retrieve values, but I can't seem to set property values.
I am using the following code:
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();
And this is not updating the profile.
I also looked up several solutions in the internet, but nothing seems to work.
The profile class looks like this:
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);
}
}
}
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还需要在 web.config 中创建属性
You also need to create the properties in the web.config
我最终使用了其他人在 Umbraco 社区网站上编写的预构建用户控件。
http://umbracoprofileeditor.codeplex.com/
I ended up using a pre-built usercontrol someone else wrote on the Umbraco community site.
http://umbracoprofileeditor.codeplex.com/