<?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>blog.dervalp.com &#187; C#</title>
	<atom:link href="http://blog.dervalp.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dervalp.com</link>
	<description>Think before Programming (Public learning)</description>
	<lastBuildDate>Sat, 20 Mar 2010 22:22:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Kiwi MVC.NET : Prepare your data access Part3</title>
		<link>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/</link>
		<comments>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/#comments</comments>
		<pubDate>Tue, 26 May 2009 20:03:45 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Kiwi MVC]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[Localized]]></category>
		<category><![CDATA[MVC.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=196</guid>
		<description><![CDATA[So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous [...]]]></description>
			<content:encoded><![CDATA[<p>So, I decide to rebuild a new solution. I will carry on the membership layer later cause I want a system who could use Sql, Active Directory or OpenID for the login and only use Sql for the membership role. I have an idea to do that but as I told you in a previous post, a security layer is a kind of plugin. Therefore, we could add it later.</p>
<p>Today, I will show you how I am going to create the models and prepare my data access with the help of LinqToSql class.</p>
<p>I choose to make Kiwi multilingual.</p>
<h2><span id="more-196"></span></h2>
<h2>1) The DB</h2>
<p>I am not a dba, you are welcome with your feedback.</p>
<p>Here is the design I choose :</p>
<p><img class="alignnone size-full wp-image-206" title="kiwi_db" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_db.jpg" alt="kiwi_db" width="833" height="780" /></p>
<h2>2) The models</h2>
<p>I decided to create five objects to begin the project. An object Post, Page, Comment, Tag and Category.</p>
<ul>
<li>The object Post : It is a content of a news (for the moment). A post must be in a category. There are status for this type. A post cannot have subposts. This object is localized</li>
</ul>
<ul>
<li>The object Page : It cannot be a part of a category, the page can have subpages. This object is localized and have the same status (puslihed, offline,&#8230;) than a post object.</li>
</ul>
<ul>
<li>The object Comment : A classic comment object, with the author name, the ip address,&#8230; A comment can have child (qutoes). This object is not localized (for the moment, we could think of an automatic translation but KISS).</li>
</ul>
<ul>
<li>The object Category :  This object contains the post. It is localized by the name.</li>
</ul>
<p>Example for Page:</p>
<p>I use the LazyList pattern (<a href="http://blog.wekeroad.com/blog/lazy-loading-with-the-lazylist/">more info here</a>). I will put the project on codeplex, like this, you will able to browse and download the code.</p>
<pre class="brush: c;">

namespace KIWI.MVC.Data
{
class Page
{
public int PageID { get; set; }
public string Author { get; set; }
public string Status { get; set; }
public DateTime Date { get; set; }
public DateTime ModifiedDate { get; set; }
public string Version { get; set; }
public string Permalink { get; set; }
public string Password { get; set; }
public LazyList&lt;Page&gt; PageChild{ get;set;}
public LazyList&lt;Page&gt; PageLozalized { get; set; }
}
public class PageLocalized
{
public string Title { get; set; }
public string Text { get; set; }
public string Excerpt { get; set; }
public string LanguageCode { get; set; }
}
}
</pre>
<h2>3) The SqlCMSRepository</h2>
<p>This repository will be the link between my object and my db. It will contain all the main method I need. I will always return an IQueryable type.  It will allow you to use the <a href="http://en.wikipedia.org/wiki/Pipes_and_filters">pipeline pattern</a> to create some filter functions.</p>
<ul>
<li>Create a LinqToSql class.</li>
</ul>
<p><img class="alignnone size-full wp-image-212" title="kiwi_linq_to_sql" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_linq_to_sql.jpg" alt="kiwi_linq_to_sql" width="683" height="414" /></p>
<p>After creating the linq to sql class, drop the table you need from the server explorer of visual studio to the dml file.</p>
<p><img class="alignnone size-full wp-image-215" title="kiwi_class_cms" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_class_cms.jpg" alt="kiwi_class_cms" width="253" height="323" /></p>
<p>You will have the representation of you db (like the first page of this post). After, change some properties of you LinqCMSRespository class. Double clik on the LinqCMDRespository.dbml and right click on the screen where your tables appear. Here change the Name to &#8220;DB&#8221;. It is only to use the same name for you future dbml and improve the visibilty of your code.</p>
<p><img class="alignnone size-full wp-image-216" title="kiwi_class_linq_properties" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_class_linq_properties.jpg" alt="kiwi_class_linq_properties" width="311" height="253" /></p>
<p>Build you solution to see if everything goes well.</p>
<p>If you have built successfully, then create you SqlCMSRespository class.</p>
<p>Here is the code :</p>
<pre class="brush: c;">
using CMS.MVC.Data.SqlRepository;

namespace CMS.MVC.Data
{
class SqlCMSRespository
{
//the name we changed in the properties of our Linq to Sql class
private DB _db;

//constructor
#region .ctor

//we instanciate the db when we instantciate the SqlCMSRespository
//default constructor
public SqlCMSRespository()
{
_db = new DB();
}

public SqlCMSRespository(DB dataContext)
{
//override the current context with the on passed in
//for TDD
_db = dataContext;
}

#endregion

#region Post
//there we will put our main functions like GetPost(),...
//But before, let's go to TDD !!!!
//TEST DRIVEN DESIGN
#endregion
}
}
</pre>
<p>Now we are able to begin all our data access method but before writing some code in your repository, we&#8217;ll go with the TDD approach.<br />
And by creating our tests, we will see what we need in our application.</p>
<p>So this is the end for today, as usual, feedback and comments are very appreciated.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d196').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d196" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;title=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3+@+http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/&amp;t=Kiwi+MVC.NET+%3A+Prepare+your+data+access+Part3" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d196').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d196').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/26/kiwi-mvc-prepare-your-data-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#.NET Create users in Active Directory</title>
		<link>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/</link>
		<comments>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/#comments</comments>
		<pubDate>Sat, 23 May 2009 02:26:16 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Adsiedit]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=122</guid>
		<description><![CDATA[I am currently working for a project in my job where I have to write an application which manage the active directory by a website application. I know that is not the best way to manage users in Active Directory but, well,&#8230;.
First, I decided to use the linq for Active Directory of Bart Desmet, I [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working for a project in my job where I have to write an application which manage the active directory by a website application. I know that is not the best way to manage users in Active Directory but, well,&#8230;.</p>
<p>First, I decided to use the linq for Active Directory of <a href="http://community.bartdesmet.net/blogs/bart/Default.aspx">Bart Desmet</a>, I know it&#8217;s a pre-alpha version but we do not have a lot of time and I really want to use all the facilities you have when you developed with linq. <a href="http://www.codeplex.com/LINQtoAD">Here is the link</a>. If you used linq to Active Directory, you should have saw that you do not have method to create. Therefore, I decided to use linq to AD for the &#8220;get&#8221; method and the &#8220;classic&#8221; method for creating users.</p>
<p>If you want to create a user in Active Directory, you should follow theses steps :</p>
<p>1) Create the user</p>
<p>2) Set the user&#8217;s password</p>
<p>3) Activate the user</p>
<h2><span id="more-122"></span>1) Create the user in active directory :</h2>
<p>I work with the respository pattern for all the data access.  So I created an ActiveDirectoryRepository where I put all the main &#8220;get&#8221; method and the create, update and delete method.</p>
<p>Here bellow, you can see my code. I create a CreateUser function in which I pass an object ActiveDirectoryUser (custom object).</p>
<p>First I set the directory entry where I want to add my user. It is quite like a connection string. With this link, the application know where he has to make his job.</p>
<p>After, I set all the properties to make a User with some basic information (name, firstname, city, country,&#8230;). When everything is set, I commit the change to active directory.</p>
<p>When it&#8217;s done, I call the ActivePassword function and the ActiveUser function. If everything goes well and if you have not received an exception error, your user in now created in the active directory and can login with the password you set during the creation. Here &#8220;newpassword&#8221;. Of course it is only to show a basic example <img src='http://blog.dervalp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><img class="alignnone size-full wp-image-126" title="create_user_ad_1" src="http://blog.dervalp.com/wp-content/uploads/2009/05/create_user_ad_1.png" alt="create_user_ad_1" width="801" height="585" /></p>
<p>Here under, the code for activate a user and set his password :</p>
<p><img class="alignnone size-full wp-image-127" title="create_user_ad_2" src="http://blog.dervalp.com/wp-content/uploads/2009/05/create_user_ad_2.png" alt="create_user_ad_2" width="806" height="452" /></p>
<p>Why 512 for the userAccountControl ? 512 is the value for a normal account in the active directory. I hardcoded it in the function but of course you can easily make some function to manage the type of user you want to create. To know more about the different possible type of user account, click <a href="http://support.microsoft.com/kb/305144">here</a>.</p>
<p>For example, if you want to have an active user with a password which expires never. You have to know the value for an active user, 512 and the value for the option &#8220;DONT_EXPIRE_PASSWORD&#8221; 65536. You add the number 512 and 65536. So, 66048 is the right number for the properties userAccountControl in this case.</p>
<p>NOTE : If you read my post about managing adam or azam account, I spoke about the support tools for Windows 2003. In these tools, there is one very usefull for developers to know where they have to put the data in. The snap in Adsiedit.msc. It shows you if the thing you are searching is a OU, a CN,&#8230; I will post more details about this tool in another post.</p>
<p>This is the end for today, if you have questions or comments, do not hesitate to leave a comment.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d122').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d122" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;title=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+C%23.NET+Create+users+in+Active+Directory+@+http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/&amp;t=C%23.NET+Create+users+in+Active+Directory" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d122').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d122').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/22/cnet-create-users-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kiwi MVC.NET : Authentication Layer, introduction Part2</title>
		<link>http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/</link>
		<comments>http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/#comments</comments>
		<pubDate>Thu, 14 May 2009 12:47:20 +0000</pubDate>
		<dc:creator>dervalp</dc:creator>
				<category><![CDATA[Kiwi MVC]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Provider]]></category>
		<category><![CDATA[Role]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.dervalp.com/?p=100</guid>
		<description><![CDATA[I know it is a bit weird to begin a CMS application by implementing a Membership system but the simple raison why I start up with that is because I needed for my work (as you can see in my previous post ).
Too often, I saw developers rewriting their own membership system in place to [...]]]></description>
			<content:encoded><![CDATA[<p>I know it is a bit weird to begin a CMS application by implementing a Membership system but the simple raison why I start up with that is because I needed for my work (as you can see in <a href="http://blog.dervalp.com/2009/05/12/azam-adam-abracanabram-%C2%BB-is-harry-potter-a-dotnet-developer-part-1-membershipprovider/" target="_blank">my previous post</a> ).</p>
<p>Too often, I saw developers rewriting their own membership system in place to use what the framework (no matter which one) can offer.</p>
<h2><span id="more-100"></span></h2>
<p>It is the main raison why I choose to implement the ASP.NET Membership system in Kiwi.  It has a lot of interesting functionalities but on the other hand it is like riding a big monster.  Thus, I am going to use it as pluggableas as I can do.</p>
<h2>The User Object :</h2>
<p>Today, creating an object called User is being strange. If you want to choose the OOP way, a user is often too generic. If you developed an e-commerce, you will certainly choose customer in place of user. But a customer and an admin can login in your system, so are-you going to create two objects? One called “customer” and the other called “vip”? That sounds weird no?</p>
<p>Here is my point of view. A membership system is for me an additional layer you can implement (or not). It is not the hearth of your application; it is just a security layer. That why I am going to use it without any &#8220;User&#8221; object.  I saw 3 mains services that a Membership system could offer :</p>
<ul>
<li> authentication (who is this guy)</li>
<li>personalization (what the guy like)</li>
<li>authorization (what the guy can do)</li>
</ul>
<h2>Sql membership :</h2>
<p>We saw in one of <a href="http://blog.dervalp.com/2009/05/12/azam-adam-abracanabram-%C2%BB-is-harry-potter-a-dotnet-developer-part-1-membershipprovider/" target="_blank">my previous post</a> that ASP.NET has 2 differents way to manage the membership layer. There we saw the active directory membership provider. Today, we will use the SqlMembershipProvider.</p>
<p>First, to use Sql membership you need a sql server with a database up. Therefore, I went to the Microsoft website to download Sql Server 2008 express and I installed it.</p>
<p>I create an empty db called Kiwi.</p>
<p>Then in the folder &#8220;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727&#8243;, I execute the aspnet_regsql.exe and provide the right information to allow the connection to the database. Finish the setup and let’s take a look on the database called Kiwi:</p>
<p><img class="alignnone size-full wp-image-105" title="kiwi_part2_1" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_1.jpg" alt="kiwi_part2_1" width="413" height="488" /></p>
<p>Now, I configure the Webconfig to use the SqlMemberShipProvider with my application.<br />
Here is the connection string I added to my webconfig file:</p>
<p><img class="alignnone size-full wp-image-107" title="kiwi_part2_2" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_2.jpg" alt="kiwi_part2_2" width="604" height="100" /></p>
<p>To test if everything works well,</p>
<p>Change the name of the connection string under membership to make the connection with your db.</p>
<p><img class="alignnone size-full wp-image-108" title="kiwi_part2_3" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_3.jpg" alt="kiwi_part2_3" width="590" height="336" /></p>
<p>Now make a test, go to the ASP.NET configuration when you are on your MVC.WEB in your website.</p>
<p><img class="alignnone size-full wp-image-109" title="kiwi_part2_4" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_4.jpg" alt="kiwi_part2_4" width="243" height="445" /></p>
<p>You will enter in the Web Site Administation Tool :</p>
<p><img class="alignnone size-full wp-image-110" title="kiwi_part2_5" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_5.jpg" alt="kiwi_part2_5" width="628" height="381" /></p>
<p>If you click on Security you will access a page where you can manage the users, the roles and the access rules.<br />
For the test, click on the “Create User” link and create one :<br />
<img class="alignnone size-full wp-image-111" title="kiwi_part2_6" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_6.jpg" alt="kiwi_part2_6" width="570" height="308" /></p>
<p>Create the user and go to the server explorer on your Visual Studio. If you do not have a connection to your db yet in server explorer, add it.</p>
<p><img class="alignnone size-full wp-image-112" title="kiwi_part2_7" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_7.jpg" alt="kiwi_part2_7" width="347" height="508" /></p>
<p>On the table aspnet_Users, right-click on Show Table Data and you will see the user you created above.</p>
<p><img class="alignnone size-full wp-image-113" title="kiwi_part2_8" src="http://blog.dervalp.com/wp-content/uploads/2009/05/kiwi_part2_8.jpg" alt="kiwi_part2_8" width="628" height="62" /></p>
<p>Cool stuff isn’t it ?<br />
Now we have a db called Kiwi with some tables created by the .NET framwork.<br />
The web application can connect to the Kiwi database and you are now able to manage user with the ASP.NET administation tools.</p>
<p>In the next post : I will begin to code with the Test driven design approach. I will create the different layer we need in our repository to make the authentication working.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d100').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d100" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/&amp;title=Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/&amp;title=Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/&amp;title=Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/&amp;title=Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/&amp;title=Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2+@+http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/&amp;t=Kiwi+MVC.NET+%3A+Authentication+Layer%2C+introduction+Part2" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://blog.dervalp.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d100').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d100').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>]]></content:encoded>
			<wfw:commentRss>http://blog.dervalp.com/2009/05/14/kiwi-mvc-authentication-layer-introduction-part2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
