1

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;
    }
}
DWright
  • 9,258
  • 4
  • 36
  • 53
Saleh Feek
  • 2,048
  • 8
  • 34
  • 56
  • @GrantWinney, I think I got it from your comment. I have a class named `Membership` but it is a default one due to installation of the Package `Microsoft.AspNet.Providers`. So there is a conflict between what you have mentioned `System.Web.Security.Membership` and the Provider's one. Thanks. – Saleh Feek Apr 26 '15 at 02:48
  • yes - either delete the question - or put your own answer and accept it if you found a colution – Scott Selby Apr 26 '15 at 03:02

1 Answers1

2

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

Saleh Feek
  • 2,048
  • 8
  • 34
  • 56