ASP.net C#。 Membership.CreateUser 方法 - 缺少引用或程序集。堆叠的

发布于 2024-08-19 18:28:24 字数 2379 浏览 1 评论 0原文

我收到错误:

错误 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; } }
}
}

i am getting error :

Error 1 The type or namespace name'CreateUser' does not exist in the namespace'LocalGarageFinder.Membership' (are you missing an assembly reference?)

I have checked the namespaces. all in. Security.Web.Security; what is missing? help please

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; } }
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谜泪 2024-08-26 18:28:24

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

Try MembershipUser newUser = System.Web.Security.Membership.CreateUser(...). It seems the compiler is looking in LocalGarageFinder.Membership, where there is indeed no CreateUser type.

陌上青苔 2024-08-26 18:28:24

这里发生了命名空间冲突。
我想您正在尝试通过调用 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); 

You've got a namespace collision going on here.
I imagine you're trying to access the asp.net membership provider with your call to Membership.CreateUser but it can't find that because it's just looking in your LocalGarageFinder.Membership namespace.

If you can't change your namespace to something a bit easier to work with, you can prefix your call to the membership provider with its full namespace.

This will change your call to:

MembershipUser newUser = System.Web.Security.Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文