This is part 2 of a number of articles looking at the basics of
using Umbraco Membership. In part 1 we
looked at creating a member through the Umbraco admin site and
adding a login page to the front end website. In this article
we will create a registration page to allow users to sign up and
log in to your website.
As with the login page in part 1 we
will use the standard asp.net membership controls to create our
registration page. I'm using the site I created in part 1 or you
could grab a free instance of Umbraco from our plans
page.
As with the login control there are a number of places our
registration control can be placed, for simplicity I'll add it
directly to a new template I've called 'Register'. As I'm
using the business starter kit, the template will need to be
created with a parent of 'Starterkit Master' and the content added
to the 'cp_content' placeholder:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
This adds an instance of the standard asp.net membership
'CreateUserWizard' control which without any customisation will
display a simple one page register control. As with most
standard membership controls the customisation
options are considerable. For more details see the MSDN page
here.
For this example I will stick with the default options.
Now that we have created a new template we need to allow a
document type to use it. Under settings -> document types
select the 'Textpage' document type and tick 'register' as an
allowed template:

Next create a new page of type 'Textpage' and tell it to use the
new 'Register' template:

If you publish the page and navigate to it you should now see a
simple, all be in unstyled register page.
The next bit is crucial and a common 'gotcha' when creating
members in Umbraco. In part 1 of this how to we created a new
member via the admin area and created a 'Customers' user group and
a 'Customer' user type. User types allow you to specify
custom properties for certain types of members, for example you may
decide to add an 'invoice number' field to all 'Customers'. I'll
cover member properties in a future article.
Member groups allow you to group your users together so you can
treat different groups of users differently. The main use is to
selectively allow groups of users access to certain pages, for
example 'customers' may be allowed to see the 'my account' page
when they login. You may also decide to send you monthly newsletter
to all members of the 'Customers' group.
When a user registers through your new page you therefore need
to specify as a minimum what type of user they are. The
simplest way to do this is to specify the 'defaultMemberTypeAlias'
attribute in the web.config file. You'll find this in the
Membership section as an attribute on the UmbracoMembershipProvider
entry. You can update this in any text editor and if you are
using our hosting either modify using an FTP client or via the
online management panel.
For our example we want new users to be of the 'Customer' type
so update the attribute accordingly:
<add
name="UmbracoMembershipProvider"
type="umbraco.providers.members.UmbracoMembershipProvider"
enablePasswordRetrieval="false" enablePasswordReset="false"
requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Customer"
passwordFormat="Hashed" />
With this attribute updated you should now be able to navigate
to your register page, complete the form and see a new member
appear in the Umbraco admin area.



In future articles we'll use our new members to selectively show
them pages and different content within pages when they are logged
in. We'll also look at member properties and using members in
C# code to perform advanced operations.