Setting up membership in Umbraco

I played around with the membership features of Umbraco tonight, and I thought I would share my findings. Mostly because it is just incredibly easy to do without even compiling any code. Just pure templates and a single entry in the web.config file is all it takes.

I started by installing the Runway package, to get a basic website.

First of all, I set up my members area with a member type and a member group:

image

Now I need to tell asp.net which Member Type I want to use when creating new users. Find this line in the web.config file:

 

<add name="UmbracoMembershipProvider"
  type="umbraco.providers.members.UmbracoMembershipProvider"
  enablePasswordRetrieval="false"
  enablePasswordReset="false"
  requiresQuestionAndAnswer="false"
  defaultMemberTypeAlias="WebsiteUser"
  passwordFormat="Hashed" />

 

Edit the attribute "defaultMemberTypeAlias" to the Member Type you want. In my case it is "WebsiteUser".

Now we are ready to create the Sign Up form. I do this in a new template, which is just a copy of the Runway Textpage, but I add the following after the body text:

<script runat="server">

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
    Roles.AddUserToRole(CreateUserWizard1.UserName, "BasicUsers");
}

protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e)
{
    Response.Redirect("/member-area.aspx");
}

</script>

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

Inside the script block I react to two events. When the user is created, I add him to the "BasicUsers" group, which is the one I will give access to my members area. The other method simply redirects the user to the member area when he finishes the signup wizard. (EDIT: Petr suggested that you use ContinueDestinationPageUrl="/member-area.aspx" instead of the redirect method, which I agree with)

Now users can sign up for membership, but we also want them to be able to log in. So we add this to the subNavigation div in the Runway Textpage template:

<asp:LoginView ID="UmbracoLoginView" runat="server">
    <AnonymousTemplate>
        <asp:Login ID="Login1" runat="server"></asp:Login>
    </AnonymousTemplate>
    <LoggedInTemplate>
        Welcome
        <asp:LoginName ID="LoginName1" runat="server" />
        <asp:LoginStatus ID="LoginStatus1" runat="server" />
    </LoggedInTemplate>
</asp:LoginView>

That is all the code that is needed. All that is left is creating content:

image

The login page is just a textpage with some text about logging in. The Sign Up page is using my new template with the CreateUserWizard control on it. The Member Area page has Public Access set like this:

image

That is all there is to it. Pretty easy huh? Feel free to post any questions in the comments, and I will try and answer to the best of my ability.

Related posts

Comments

Comments disabled

Comments are disabled for this post.