ASP.net C#。 Membership.CreateUser方法 - 缺少引用或汇编。堆叠

时间:2010-01-31 17:50:31

标签: asp.net asp.net-membership

我收到错误:

  

错误1名称空间'LocalGarageFinder.Membership'中不存在类型或命名空间名称'CreateUser'(您是否缺少程序集引用?)

我检查过命名空间。全押.Security.Web.Security;缺什么?请帮忙

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.Security;

namespace LocalGarageFinder.Membership
{
    public partial class CreatingUserAccounts : System.Web.UI.Page
    {
        const string passwordQuestion = "What is your favorite color";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) SecurityQuestion.Text = passwordQuestion;
        }

        protected void CreateAccountButton_Click(object sender, EventArgs e) 
        { 
          MembershipCreateStatus createStatus; 
          MembershipUser newUser = Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus); 

            switch (createStatus) 
            { case MembershipCreateStatus.Success: CreateAccountResults.Text = "The user account was successfully created!";
                   break; 
              case MembershipCreateStatus.DuplicateUserName: CreateAccountResults.Text = "There already exists a user with this username."; 
                   break;
              case MembershipCreateStatus.DuplicateEmail: CreateAccountResults.Text = "There already exists a user with this email address."; 
                   break; 
              case MembershipCreateStatus.InvalidEmail: CreateAccountResults.Text = "There email address you provided in invalid."; 
                    break; 
             case MembershipCreateStatus.InvalidAnswer: CreateAccountResults.Text = "There security answer was invalid."; 
                    break; 
             case MembershipCreateStatus.InvalidPassword: CreateAccountResults.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";
                    break; 
             default: CreateAccountResults.Text = "There was an unknown error; the user account was NOT created."; 
                 break; } }
}
}

2 个答案:

答案 0 :(得分:1)

你在这里发生了一个命名空间冲突。 我想你正试图通过调用Membership.CreateUser来访问asp.net会员提供者,但它找不到它,因为它只是在你的LocalGarageFinder.Membership命名空间中查找。

如果您无法将名称空间更改为更容易使用的名称空间,则可以使用其完整名称空间将您的调用前缀添加到成员资格提供程序。

这会将您的电话更改为:

MembershipUser newUser = System.Web.Security.Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus); 

答案 1 :(得分:1)

试试MembershipUser newUser = System.Web.Security.Membership.CreateUser(...)。似乎编译器正在查看LocalGarageFinder.Membership,其中确实没有CreateUser类型。