<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Peder Borg Borup &#187; asp.net</title> <atom:link href="http://www.pederborg.dk/category/aspnet/feed/" rel="self" type="application/rss+xml" /><link>http://www.pederborg.dk</link> <description>Just another WordPress weblog</description> <lastBuildDate>Sat, 04 Jun 2011 06:54:33 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Howto: ASP.NET Membership and Roles using SQL Server</title><link>http://www.pederborg.dk/2007/06/17/howto-aspnet-membership-and-roles-using-sql-server/</link> <comments>http://www.pederborg.dk/2007/06/17/howto-aspnet-membership-and-roles-using-sql-server/#comments</comments> <pubDate>Sun, 17 Jun 2007 10:29:32 +0000</pubDate> <dc:creator>Peder Borg Borup</dc:creator> <category><![CDATA[asp.net]]></category> <category><![CDATA[Visual Basic .NET]]></category><guid
isPermaLink="false">http://tech.pederborgpoulsen.dk/2007/06/17/howto-aspnet-membership-and-roles-using-sql-server/</guid> <description><![CDATA[In this short guide, I&#8217;ll show how to use a dedicated SQL Server for the Membership and Roles part of ASP.NET. Normally the membership and roles uses the local SQL Express Server and a aspnetdb in the local app_data directory of the webserver. But for many reasons (one of them central backup) I have always [...]]]></description> <content:encoded><![CDATA[<p>In this short guide, I&#8217;ll show how to use a dedicated SQL Server for the Membership and Roles part of ASP.NET. Normally the membership and roles uses the local SQL Express Server and a aspnetdb in the local app_data directory of the webserver. But for many reasons (one of them central backup) I have always wanted to be able to use my existing SQL Server (in my case SQL Server 2005).</p><p>1) Create a new database on your SQL Server to hold the membership and roles.</p><p>2) In my case I&#8217;ll create a new ASP.NET website to use for this demo. The website will be called &quot;demo_membership&quot;.</p><p>3) Populate the database you created with the membership tables. For this, you&#8217;ll use the program aspnet_regsql located in: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 &#8211; doubleclick to launch.</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114651-1074.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="190" alt="screenshot-20070617-114651-1074" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114651-1074-thumb.jpg" width="244" border="0" /></a> <a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114712-1075.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="190" alt="screenshot-20070617-114712-1075" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114712-1075-thumb.jpg" width="244" border="0" /></a></p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114744-1076.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="190" alt="screenshot-20070617-114744-1076" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114744-1076-thumb.jpg" width="244" border="0" /></a>&#160; <a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114752-1077.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="190" alt="screenshot-20070617-114752-1077" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114752-1077-thumb.jpg" width="244" border="0" /></a></p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114813-1078.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="190" alt="screenshot-20070617-114813-1078" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-114813-1078-thumb.jpg" width="244" border="0" /></a></p><p>If you expand the database &#8211; you should see the membership/roles tables:</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-115022-1079.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="screenshot-20070617-115022-1079" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-115022-1079-thumb.jpg" width="202" border="0" /></a></p><p>The database is now reade for use.</p></p><p><span
id="more-59"></span></p><p>4) Next you&#8217;ll have to edit the web.config file of your web-project to include information to use the SQL Server instead of the local SQL Express.</p><p>5) Add a connection-string that points to your membership database:</p><blockquote><p> &lt;connectionStrings&gt; <br
/>&#160;&#160; &lt;add name=&quot;CS_DemoMembership&quot; connectionString=&quot;Data Source=10.0.0.64;Initial Catalog=DemoMembership;Persist Security Info=True;User ID=DemoMembership;Password=demo&quot; <br
/>providerName=&quot;System.Data.SqlClient&quot; /&gt; <br
/> &lt;/connectionStrings&gt;</p></blockquote><p>6) Add membership-provider (in system.web):</p><blockquote><p>&lt;membership&gt; <br
/>&#160; &lt;providers&gt; <br
/>&#160;&#160;&#160; &lt;remove name=&quot;AspNetSqlMembershipProvider&quot;/&gt; <br
/>&#160;&#160;&#160; &lt;add name=&quot;AspNetSqlMembershipProvider&quot; <br
/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; type=&quot;System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; <br
/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connectionStringName=&quot;CS_DemoMembership&quot; <br
/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; applicationName=&quot;/&quot; /&gt; <br
/>&#160; &lt;/providers&gt; <br
/>&lt;/membership&gt;</p></blockquote><p>7) Add profile-provider (in system.web):</p><blockquote><p>&lt;profile&gt; <br
/>&#160; &lt;providers&gt; <br
/>&#160;&#160;&#160; &lt;remove name=&quot;AspNetSqlProfileProvider&quot;/&gt; <br
/>&#160;&#160;&#160; &lt;add name=&quot;AspNetSqlProfileProvider&quot; connectionStringName=&quot;CS_DemoMembership&quot; applicationName=&quot;/&quot; <br
/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; type=&quot;System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; /&gt; <br
/>&#160; &lt;/providers&gt; <br
/>&lt;/profile&gt;</p></blockquote><p> <img
src='http://pedborwordpress.s3.amazonaws.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> Add roles-provider (in system.web):</p><blockquote><p>&lt;roleManager enabled=&quot;true&quot;&gt; <br
/>&#160; &lt;providers&gt; <br
/>&#160;&#160;&#160; &lt;remove name=&quot;AspNetSqlRoleProvider&quot;/&gt; <br
/>&#160;&#160;&#160; &lt;remove name=&quot;AspNetWindowsTokenRoleProvider&quot;/&gt; <br
/>&#160;&#160;&#160; &lt;add name=&quot;AspNetSqlRoleProvider&quot; connectionStringName=&quot;CS_DemoMembership&quot; applicationName=&quot;/&quot; <br
/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; type=&quot;System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; /&gt; <br
/>&#160;&#160;&#160; &lt;add name=&quot;AspNetWindowsTokenRoleProvider&quot; applicationName=&quot;/&quot; <br
/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; type=&quot;System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; /&gt; <br
/>&#160; &lt;/providers&gt; <br
/>&lt;/roleManager&gt;</p></blockquote><p>9) The reasen why the &lt;remove name&gt; tags are added is, that by default, the machine.config file is read, which contains these keys. As you wish to use your own keys, you have to remove the ones read from the machine.config-file.</p><p>10) My website looks like this:</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-120941-1080.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="157" alt="screenshot-20070617-120941-1080" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-120941-1080-thumb.jpg" width="244" border="0" /></a></p><p>- and I wan&#8217;t to protect the &quot;admin&quot;-folder.</p><p>11) Fire up the ASP.NET Configuration Tool (Website -&gt; ASP.NET Configuration)</p><p>12) Select &quot;Security&quot; and make sure that &quot;From Internet&quot; is chosen.</p><p>13) Add a user.</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121159-1082.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="145" alt="screenshot-20070617-121159-1082" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121159-1082-thumb.jpg" width="244" border="0" /></a></p><p>14) To check that the user was created select &quot;Manage Users&quot;:</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121217-1083.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="71" alt="screenshot-20070617-121217-1083" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121217-1083-thumb.jpg" width="244" border="0" /></a></p><p>15) Add a role &#8211; and add the user to this role.</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121554-1085.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="72" alt="screenshot-20070617-121554-1085" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121554-1085-thumb.jpg" width="244" border="0" /></a></p><p>16) Secure the &quot;admin&quot;-folder:</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121637-1086.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="102" alt="screenshot-20070617-121637-1086" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121637-1086-thumb.jpg" width="244" border="0" /></a></p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121713-1087.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="62" alt="screenshot-20070617-121713-1087" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121713-1087-thumb.jpg" width="244" border="0" /></a></p><p>17) Just to show you &#8211; the users and roles actually are in the database on the SQL Server:</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121902-1088.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="41" alt="screenshot-20070617-121902-1088" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121902-1088-thumb.jpg" width="244" border="0" /></a> <a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121920-1089.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="34" alt="screenshot-20070617-121920-1089" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-121920-1089-thumb.jpg" width="244" border="0" /></a></p><p>18) Create a login-control on a public page.</p><p>19) Open the web-page, login, and you should be redirected to the secure-page:</p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-122113-1090.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="128" alt="screenshot-20070617-122113-1090" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-122113-1090-thumb.jpg" width="244" border="0" /></a></p><p><a
href="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-122652-1092.jpg"><img
style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="34" alt="screenshot-20070617-122652-1092" src="http://pedborwordpress.s3.amazonaws.com/wp-content/uploads/2008/04/screenshot-20070617-122652-1092-thumb.jpg" width="244" border="0" /></a></p><div
class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:a1ba2046-a1ea-4678-b697-98a7030cb490" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati tags: <a
href="http://technorati.com/tags/asp.net" rel="tag">asp.net</a>, <a
href="http://technorati.com/tags/membership" rel="tag">membership</a>, <a<br
/> href="http://technorati.com/tags/roles" rel="tag">roles</a>, <a
href="http://technorati.com/tags/sql%20server" rel="tag">sql server</a></div> ]]></content:encoded> <wfw:commentRss>http://www.pederborg.dk/2007/06/17/howto-aspnet-membership-and-roles-using-sql-server/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching 10/18 queries in 0.023 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: pedborwordpress.s3.amazonaws.com

Served from: www.pederborg.dk @ 2012-02-07 10:34:29 -->
