Search code examples
c#asp.netmembership-providercreateuserwizard

Membership.GetUser -> Membership doesn't contain a definition for 'GetUser'. What have I missed?


MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName);

I get a red line under GetUser and when I hover over it, a message appears:

Membership doesn't contain a definition for 'GetUser'

When I click the small dash below GetUser I get:

Generate method stub for 'GetUser' in 'Membership

What have I missed?

ASPX:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatedUser="CreateUserWizard1_CreatedUser" >
    <WizardSteps>
        <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
        </asp:CreateUserWizardStep>
        <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
        </asp:CompleteWizardStep>
    </WizardSteps>
</asp:CreateUserWizard>

Code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class SignUp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName);
        Guid newUserId = (Guid)newUser.ProviderUserKey;
    }
}

Solution

  • The problem is due to existence of a class with the same name Membership. The one already defined doesn't have a definition for the method GetUser.
    What you actually need for the code to work is to call the full namespace of the classMembership to differentiate between the two; the alreadey defined one and the intended one. The intended one can be referred to by: System.Web.Security.Membership

    Instead of this: MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName);

    Use this:
    MembershipUser newUser = System.Web.Security.Membership.GetUser(CreateUserWizard1.UserName);