0

嗨,我是 umbraco 的新手

我最近做了一个登录和注册页面并使用 umbraco.cms.businesslogic.member.Member

登录工作正常

但是在注册过程中,在检查以前存在的用户时会出错

这是 Register.aspx.cs 代码

using System;
using System.Web.Security;
using System.Web.UI;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.member;

namespace membershipc
{
    public partial class Register : System.Web.UI.UserControl
    {
        // Macro Parameters
        public int SuccessfulLoginPage { get; set; }

        // Member Type & Group
        private const string MembersType = "SiteMembers";
        private const string MembersGroup = "SiteMembers";

        // Error format
        private const string ErrorFormat = "<p class=\"formerror\">{0}</p>";

        protected void RegisterPlayer(object sender, EventArgs e)
        {
            // Do some server side checks just to be on the safe side
            if (string.IsNullOrWhiteSpace(tbEmail.Text) | string.IsNullOrWhiteSpace(tbPassword.Text) | string.IsNullOrWhiteSpace(tbUsername.Text))
            {
                litError.Text = string.Format(ErrorFormat, "Please complete all fields");
                return;
            }

            // Check the user isn't already registered
            **if ((Member.GetMemberFromEmail(tbEmail.Text) == null) && (Member.GetMemberFromLoginName(tbUsername.Text) == null))**
            {
                // Set the member type and group
                var mt = MemberType.GetByAlias(MembersType);
                var addToMemberGroup = MemberGroup.GetByName(MembersGroup);

                //create the member, and set the password and email
                var m = Member.MakeNew(tbUsername.Text, mt, new User(0));
                m.Password = tbPassword.Text;
                m.Email = tbEmail.Text;

                // Add the member to the group
                m.AddGroup(addToMemberGroup.Id);

                //Save member
                m.Save();

                //Generate member Xml Cache
                m.XmlGenerate(new System.Xml.XmlDocument());

                // NOTE: This Is Optional
                // Login the user
                FormsAuthentication.SetAuthCookie(tbUsername.Text, false);

                // Redirect to successful page (Usually their profile or member page)
                Response.Redirect(library.NiceUrl(SuccessfulLoginPage));
            }
            else
            {
                // Error, member already exists with email or username used
                litError.Text = string.Format(ErrorFormat, "User already exists");
            }
        }
    }
}

我无法理解为什么它会出错请帮助我

4

2 回答 2

1

您需要检查您的 web.config 文件中的成员资格提供程序是否设置正确,因为您的实例似乎Member为空。

确保您使用与 Umbraco 安装时相同的配置设置。如有疑问,请再次下载您的版本并检查原始 web.config 设置。

更新:

检查 web.config 中是否设置了默认成员类型:

<membership
    defaultProvider="UmbracoMembershipProvider"
    userIsOnlineTimeWindow="15"
    defaultMemberTypeAlias="SiteMembers"
/>
于 2013-07-08T14:11:49.653 回答
0

只需更改 webconfig 文件中的语句即可解决问题

defaultMemberTypeAlias="Another Type" 

defaultMemberTypeAlias="SiteMembers"

SiteMembers 是我在 umbraco 后台创建的类型

于 2013-07-09T11:06:29.580 回答