Setting up membership in Umbraco
Published on 01. april 2009 inI 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:
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:
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:
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.

On 01. april 2009 by Simon Probert
Awesome - I literally was just about to implement member logins and found this post. How easy can it possibly get? You umbraco guys rock!
SP aka Spacecowboy
On 01. april 2009 by Hendy
Isn't it great that Umbraco v4 has adopted .net standards such as the membership provider model you've described here; all the regular asp.net membership controls now work directly out of the box :)
On 01. april 2009 by Dirk
Great article!
Now I've got a link to provide when more questions arise in the forum.
Thanks for sharing...
Cheers,
Dirk
On 01. april 2009 by Ismail
Morten,
That is as easy as falling of a log! Excellent and useful post.
Regards
Ismail
On 05. april 2009 by Petr Snobelt
Hi,
nice post,
you should use ContinueDestinationPageUrl="/member-area.aspx" instead of redirect in code.
Petr
On 05. april 2009 by Morten Bock
Thanks for the tip Petr. That would surely be a better solution.
On 06. maj 2009 by Siw
Hi Morten, I like your article, but it's too simple for my current taks. Hope you have time for this.
I have a new site where member area content consist of 3 different info blocks. Each of these has 2 access levels. Users will have access to 1, 2 or all 3 areas, on low or full access level. So can I take advantage of the membership functionality to achieve this kind of differentiated access without programming "anything"? I'm sorry I'm not very insightfull here. Hope you have some advice for me. And maybe you can mail me.
On 08. maj 2009 by saintwright
That was really helpful - However I am stuck with adding custom fields to the register form - e.g. City, First Name, Last Name etc......
On 16. maj 2009 by Digby
Thanks for this it has worked fine for me.
The basic asp.net login control doesn't provide many styling options. If you create a page in vs with a login control and then right click and choose Convert to template.. this gives you the expanded control which can be copied in place of the asp:Login in your example which you can then style as necessary.
On 04. juni 2009 by Lee Atkinson
Hi
Thanks for your article. DO you know if it's possible to get membership to work with directory urls (e.g. without .aspx extensions)?
It doesn't work for me - it doesn't reply with an error when I login with the correct username and password, but I get an ASP.NET error when I access a page, and doesn't show anything.
For now, I've fixed it using IIS Url Rewrite module but this isn't ideal as .aspx links still exist during postbacks.
Lee
On 29. juni 2009 by Dave
Great post! Anyone know how I can change the value of the submit button from "Create User"?
On 29. juni 2009 by Dave
Nevermind, figured it out:
On 28. juli 2009 by Tom
Thanx!
You have opend a whole new world for me :)
On 18. november 2009 by Shaun Chatterton
Hi. thanks for the article!
I've tried to use part of it, namely only the login part, to create a login for my site. However, on successfully logging in the page does not redirect correctly. the url looks correct but the page still contains the login control and does not contain the correct template. Any idea what I'm doing wrong?