版本7中的UmbracoMemberProfileProvider不存在,有什么替代品?

时间:2015-01-09 15:03:18

标签: asp.net umbraco profile member

我正在从umbraco v6.0.5升级到v7.2.1。

在我当前的(v6)web.config中,我有以下内容:

<profile defaultProvider="UmbracoMemberProfileProvider" enabled="true" inherits="NFOPP.Website.usercontrols.Security.MemberProfile, NFOPP.Website">
      <providers>
        <clear />
        <add name="UmbracoMemberProfileProvider" type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />
      </providers>
      <properties>
        <clear />
        <add name="_title" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
        <add name="_firstname" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
        <add name="_lastname" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
        <add name="_memberNumber" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
      </properties>
    </profile>

我也有这样的课程:

public class MemberProfile : ProfileBase
    {
        #region Firstname
        private const string FIRSTNAME = "_firstname";
        [SettingsAllowAnonymous(false)]
        public string FirstName
        {
            get
            {
                return GetCustomProperty(FIRSTNAME);
            }
            set
            {
                SetCustomProperty(FIRSTNAME, value);
            }
        } 
        #endregion

        #region Get and Set base properties

        private string GetCustomProperty(string propertyName)
        {
            var retVal = "";
            var prop = base.GetPropertyValue(propertyName);
            if (prop != null)
            {
                retVal = prop.ToString();
            }
            return retVal;
        }
        private void SetCustomProperty(string propertyName, object value)
        {
            var prop = base[propertyName];
            if (prop != null)
            {
                base.SetPropertyValue(propertyName, value);
            }
        }

        #endregion
    }

这样做的目的是让我可以使用我的MemberProfile对象并直接访问它的属性,如FirstName。

“umbraco.providers.members.UmbracoProfileProvider”似乎不存在(除非我弄错了)任何更多的意思我似乎无法连接一个正确覆盖“ProfileBase”的类,当我尝试加载一个访问“MemberProfile”对象的页面,它表示“没有PropertyType,并且提供的别名为_firstname”

有更好的方法可以做到这一点,而在v7中,如果没有提供商,实际上还需要配置部分吗?

解决方案已实施:

我在会员档案类中添加了以下方法:

public static MemberProfile Get(IMemberService memberService, UmbracoContext context)
        {
            var membershipHelper = new Umbraco.Web.Security.MembershipHelper(context);

            var profileModel = membershipHelper.GetCurrentMemberProfileModel();
            if (profileModel != null)
            {
                return Get(profileModel.UserName, memberService);
            }
            else
            {
                return null;
            }
        }

        public static MemberProfile Get(string userName, IMemberService memberService)
        {
            var member = memberService.GetByUsername(userName);

            return new MemberProfile(member);
        }

我还更新了Get和Set属性方法,如下所示:

#region Get and Set base properties

        private string GetCustomProperty(string propertyName)
        {
            var retVal = "";
            if (_member.Properties.IndexOfKey(propertyName) > -1)
            {
                var prop = _member.Properties[propertyName];

                if (prop != null && prop.Value != null)
                {
                    retVal = prop.Value.ToString();
                }
            }
            return retVal;
        }
        private void SetCustomProperty(string propertyName, object value)
        {
            if (_member.Properties.IndexOfKey(propertyName) > -1)
            {
                var prop = _member.Properties[propertyName];
                if (prop != null)
                {
                    prop.Value = value;
                }
            }
        }

        #endregion

为了使用它,我在需要成员对象的任何地方调用了以下内容:

var member = MemberProfile.Get(ApplicationContext.Current.Services.MemberService, Umbraco.Web.UmbracoContext.Current);

我仍然感谢您对此解决方案的任何想法,以及其他人如何处理向成员添加自定义属性以及如何从代码中访问它们。

1 个答案:

答案 0 :(得分:1)

这是我的心,但我认为你仍然有像这样的基于asp.net的个人资料提供者:

<profile defaultProvider="UmbracoMemberProfileProvider" enabled="true" inherits= "Umbarco.Models.MemberProfile, Umbarco">

考虑使用新的Membership API introduced in v7.1