嗨,我是 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");
}
}
}
}
我无法理解为什么它会出错请帮助我