ASP.NET 会员资料更新

发布于 2024-11-02 16:41:58 字数 3047 浏览 1 评论 0原文

我正在处理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赤濁 2024-11-09 16:41:58

您还需要在 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>

You also need to create the properties in the 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>
溺渁∝ 2024-11-09 16:41:58

我最终使用了其他人在 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文