我正在使用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);
}
}
}
谢谢!
最佳答案
您还需要在web.config中创建属性
<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" />
<add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" />
</providers>
<properties>
<add name="auth_guid" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />
<add name="fullName" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />
<add name="country" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />
<add name="streetAddress" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />
<add name="phoneNumber" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />
<add name="city" allowAnonymous ="false" provider="UmbracoMemberProfileProvider" type="System.String" />
</properties>
</membership>
关于c# - asp.net成员(member)资料更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5761655/