{"id":419,"date":"2009-04-23T03:42:00","date_gmt":"2009-04-23T12:42:00","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/2009\/04\/23\/create-a-minimal-asp-net-membership-website-that-will-come-in-useful-in-another-post\/"},"modified":"2009-04-23T03:42:00","modified_gmt":"2009-04-23T12:42:00","slug":"create-a-minimal-asp-net-membership-website-that-will-come-in-useful-in-another-post","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2009\/04\/23\/create-a-minimal-asp-net-membership-website-that-will-come-in-useful-in-another-post\/","title":{"rendered":"Create a Minimal ASP.NET Membership Website (that will come in useful in another post)"},"content":{"rendered":"<p><DIV class=\"wlWriterHeaderFooter\"><br \/>\ndigg_url = &#8220;http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/create-a-minimal-asp-net-membership-website-that-will-come-in-useful-in-another-post.aspx&#8221;;digg_title = &#8220;Create a Minimal ASP.NET Membership Website (that will come in useful in another post)&#8221;;digg_bgcolor = &#8220;#FFFFFF&#8221;;digg_skin = &#8220;normal&#8221;;<\/p>\n<p>digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;<br \/>\n<\/DIV><br \/>\n<P>This post contains no special considerations or insights, and is just meant to provide a base for <A href=\"http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/enhance-your-asp-net-membership-based-website-by-adding-identity-provider-capabilities.aspx\">the post here<\/A>. If you are familiar with ASP.NET membership, DON\u2019T READ THIS and go straight <A href=\"http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/enhance-your-asp-net-membership-based-website-by-adding-identity-provider-capabilities.aspx\">here<\/A>. This is just a walkthrough which helps you to create a certain ASP.NET website which takes advantage of the membership provider authentication mechanism and that I use as a starting example in <A href=\"http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/enhance-your-asp-net-membership-based-website-by-adding-identity-provider-capabilities.aspx\">another post<\/A>. We have excellent walkthroughs in MSDN on this topic (see <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/879kf95c(VS.80).aspx\">this<\/A>) however 1) this is a specific example and 2) if you are not familiar with our platform, here I added a lot of screenshots that may make your life easier.<\/P><br \/>\n<P>Let\u2019s say that we want to create a club website, where all the members are software architects who happen to have long hair (or an interest in growing them). We will use a sql membership provider store, we will create users, assign roles and use role info for granting or denying access to parts of the website.<\/P><br \/>\n<P>The first step is creating the website:<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_c2e44e6b-018f-4002-981c-d6ae3acf2f43.png\" width=\"504\" height=\"326\"> <\/P><br \/>\n<P>The result is a classic one-page website, with&nbsp; no special security settings.<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_a263ea4c-d4a0-4678-8f94-db439db51bf3.png\" width=\"404\" height=\"166\"> <\/P><br \/>\n<P>Let\u2019s go to the Website menu and choose ASP.NET Configuration: <\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_7ad489b1-e615-44a0-bbba-1f49f9dfdb06.png\" width=\"254\" height=\"339\"> <\/P><br \/>\n<P>We\u2019ll end up on the site admin tool, which will allow us to add &amp; configure our membership store<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_62e12fb3-31a2-4de5-ab99-2bb1abaf139a.png\" width=\"504\" height=\"370\"> <\/P><br \/>\n<P>Let\u2019s choose \u201cuse the security setup wizard..\u201d<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_c9204c9d-edb5-416d-9b17-b2603daa3880.png\" width=\"504\" height=\"323\"> <\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>Standard splash screen: let\u2019s move on<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_755b6b6c-9da9-48bb-828f-f4e58697c69b.png\" width=\"504\" height=\"324\"> <\/P><br \/>\n<P>Our users will be from the public internet, let\u2019s pick the right selection and move on<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_76123db9-ed7e-46b6-8f9f-66e5e5d0943c.png\" width=\"504\" height=\"323\"> <\/P><br \/>\n<P>We do want roles.<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_bb2626e9-a825-4876-8e5b-73891b151ed0.png\" width=\"504\" height=\"325\"> <\/P><br \/>\n<P>Let\u2019s add some roles which represent different hair lengths<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_0432ca3b-d35c-4028-b92d-55c317b2c792.png\" width=\"504\" height=\"324\"> <\/P><br \/>\n<P>OK, you had enough fun already! four are more than enough \ud83d\ude42<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_bf69e472-da64-4861-b7cb-23c52926e608.png\" width=\"504\" height=\"326\"> <\/P><br \/>\n<P>Let\u2019s add some users: at least two, so that we can experiment with different role assignments<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_d0ecd456-602e-4208-888e-6eee7611a7f7.png\" width=\"504\" height=\"334\"> <\/P><br \/>\n<P>Let\u2019s deny be default, and we\u2019re almost done.<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_037db276-7e63-44d0-997d-3cc1ce37103b.png\" width=\"504\" height=\"334\"> <\/P><br \/>\n<P>Now that we defined both users and roles, we need to assign the latter to the formers:<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_7220702d-a380-4ebe-9ae4-12a936564ef7.png\" width=\"504\" height=\"333\"> <\/P><br \/>\n<P>The UI makes it very easy<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_612d9a8a-931d-4966-b477-82f636b720bb.png\" width=\"504\" height=\"335\"> <\/P><br \/>\n<P>Once we assigned few roles, we can go back to the app.<\/P><br \/>\n<P>Let\u2019s customize the default page a bit: green background, some text, and a LoginStatus control that we can use for controlling the session (ie sign out if we are signed in &amp; viceversa) <\/P><br \/>\n<P>&nbsp;<IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_9d634214-74b8-44c9-bb81-57446075bb4e.png\" width=\"504\" height=\"204\"> <\/P><br \/>\n<P>If we want to be even more adaptive, we can add a LoginName control in the text for personalized greetings<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_f2cd0dec-a820-4b91-a1e3-8356ebe1816d.png\" width=\"504\" height=\"140\"> <\/P><br \/>\n<P>Now hat we have a users store, we need a page for gathering credentials and interrogate it. Let\u2019s add a login.aspx page:<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_ee4352b3-3166-4ecf-8cc2-847217f3375a.png\" width=\"504\" height=\"329\"> <\/P><br \/>\n<P>Let\u2019s drag a Login control in there: that should do.<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_6a9257f1-fad9-4ff4-bbb4-1850e262313a.png\" width=\"504\" height=\"232\"> <\/P><br \/>\n<P>Now that we have our default and login pages, let\u2019s add an extra page to demonstrate how to restrict content only to specific roles:<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_96f75133-b3e7-4dfe-9a29-23629fd6b765.png\" width=\"504\" height=\"332\"> <\/P><br \/>\n<P>Write some nonsense in it, make it very recognizable (ie different background than the rest of the website, for example) and we\u2019re done.<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_51e71e2c-e55b-46ca-8a77-e6f5a61e12ac.png\" width=\"504\" height=\"249\"> <\/P><br \/>\n<P>Let\u2019s add a link to the restricted page from the home page:<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_a71b62ea-d791-4a84-8e00-cf0e756efcec.png\" width=\"604\" height=\"389\"> <\/P><br \/>\n<P>Restricting the access to the page is easy: you just add the code fragment below in the web.config. That code means that only the members belonging to the role chewbacca can access the page.<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_9e4a61c4-dd97-409b-a98e-41e07560c235.png\" width=\"404\" height=\"214\"> <\/P><br \/>\n<P>Let\u2019s give the website a spin. If you navigate to the default.aspx page, since you are not authenticated you\u2019ll end up being redirected to the login page<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_1e9ca08f-fee3-45b0-826c-20111bf77c65.png\" width=\"382\" height=\"247\"> <\/P><br \/>\n<P>Note in fact the address<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_9564f5e2-e559-4a9f-b0d6-d08c47091dd3.png\" width=\"604\" height=\"54\"> <\/P><br \/>\n<P>Once we enter the right credentials, we are in. <\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_03b6cbb0-01a9-49a6-b945-a8268c5ba2ce.png\" width=\"504\" height=\"203\"> <\/P><br \/>\n<P>If the user does not belong to the chewbacca role, he\u2019ll be bounced back when trying to follow the exclusive content link. Let\u2019s logout and sign in with a user that is in the chewbacca role:<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_7dc6da50-f1da-4a9e-b706-639774ed7e08.png\" width=\"504\" height=\"173\">&nbsp;<\/P><br \/>\n<P><IMG title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/04\/image_387e7298-1ce9-48e1-a41e-5a770b16de3a.png\" width=\"504\" height=\"152\"><\/P><br \/>\n<P>This time we can successfully access the restricted page.<\/P><br \/>\n<P>That\u2019s it. As promised, nothing esoteric: no prescriptive guidance or best practices, just a little walkthrough for a trivial sample. I just needed a normal membership provider ASP.NET site as a starting point for the <A href=\"http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/enhance-your-asp-net-membership-based-website-by-adding-identity-provider-capabilities.aspx\">next post<\/A> but 1) i didn\u2019t want to spoil the signal\/noise ratio of that post by adding instructions that are not useful for many readers while at the same time 2) i didn\u2019t want to leave out the readers who are not too familiar with the membership.<\/P><br \/>\n<P>On to the <A href=\"http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/enhance-your-asp-net-membership-based-website-by-adding-identity-provider-capabilities.aspx\">next post<\/A>, where you\u2019ll find the real substance \ud83d\ude42<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>digg_url = &#8220;http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/04\/23\/create-a-minimal-asp-net-membership-website-that-will-come-in-useful-in-another-post.aspx&#8221;;digg_title = &#8220;Create a Minimal ASP.NET Membership Website (that will come in useful in another post)&#8221;;digg_bgcolor = &#8220;#FFFFFF&#8221;;digg_skin = &#8220;normal&#8221;; digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined; This post contains no special considerations or insights, and is just meant to provide a base for the post here. If you&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1411,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-identity"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=419"}],"version-history":[{"count":0,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/419\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media\/1411"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}