<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tweet with Sundeep Podugu</title>
	<atom:link href="http://stweet.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://stweet.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 30 Dec 2011 02:13:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='stweet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/8653b10fbb244c1d20f601476fba7b46?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Tweet with Sundeep Podugu</title>
		<link>http://stweet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://stweet.wordpress.com/osd.xml" title="Tweet with Sundeep Podugu" />
	<atom:link rel='hub' href='http://stweet.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A small tribute to big achievers</title>
		<link>http://stweet.wordpress.com/2011/07/06/a-small-tribute-to-big-achievers/</link>
		<comments>http://stweet.wordpress.com/2011/07/06/a-small-tribute-to-big-achievers/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 21:27:07 +0000</pubDate>
		<dc:creator>Sundeep Podugu</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://stweet.wordpress.com/2011/07/06/a-small-tribute-to-big-achievers/</guid>
		<description><![CDATA[Last month I read an article on yahoo about damage caused by Joplin, Missouri tornado. I felt sad for the loss of many lives and as I read through the article, I came across couple of people who inspired me and I don&#8217;t want to miss the opportunity to share it with you. One amongst [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=345&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last month I read an article on yahoo about damage caused by Joplin, Missouri tornado. I felt sad for the loss of many lives and as I read through the article, I came across couple of people who inspired me and I don&#8217;t want to miss the opportunity to share it with you.
</p>
<p>One amongst them was <strong>Will Norton</strong>, 18-year old young man graduated from the high school the day when the tornado struck. He and his father, Mark, were driving back home from the high school commencement ceremony and tornado has sucked him out of the vehicle. His dad tried to hold unto him but unfortunately he couldn&#8217;t make it. He went missing for five days and finally search ended after his body was found in a pond. His dad suffered many injuries and currently he is recuperating.
</p>
<p>I felt sad for him for that moment, but when I read his profile and his achievements, I had smile on my face. I was awestruck with all his activities and achievements in such young age. He was a famous <a href="http://www.youtube.com/user/willdabeast88883333" target="_blank">you tuber</a>.
</p>
<p>As a Christian, I am attracted to his last days of his life.  <a href="http://twitter.com/WillNorton" target="_blank">He</a> tweeted below verse day before the tornado.
</p>
<p><em>&#8220;But about that day or hour no one knows, not even the angels in heaven, nor the Son, but only the Father.&#8221; Matthew 24:36<strong><br />
			</strong></em></p>
<p>During his last moments in the car, he recited bible verses. This made me think that he knew his destination and he was well prepared for it.  Praise the Lord! Though one can argue that it is mere coincidence, but the truth of death is inevitable and what matters is how we live this short life.
</p>
<p> I was also inspired by their family. They made it feel that it&#8217;s no loss but he is in much better place, Heaven. His sister Sarah has done a <a target="_blank" href="http://www.youtube.com/watch?v=BVSeptS3kec">great video</a> sharing their experience about the incident. They had created a <a href="http://www.facebook.com/FindWillNorton" target="_blank">facebook page</a> and organizing social activities in his memory.
</p>
<p>Other person is <strong>Don Lansaw</strong>, also a victim of the Joplin tornado. He sacrificed his life for his wife, Bethany Lansaw, while covering her with his body during the horrific incident and finally succumbed to injuries. It was a heart touching moment of true love and <a href="http://www.dailymail.co.uk/news/article-1391145/Joplin-MO-tornado-Wife-talks-moment-husband-gave-life-save-her.html" target="_blank">this video</a> is the testimony of Bethany Lawson.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stweet.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stweet.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stweet.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stweet.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stweet.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stweet.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stweet.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stweet.wordpress.com/345/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=345&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stweet.wordpress.com/2011/07/06/a-small-tribute-to-big-achievers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/407a17e18d46593d3acfda3ad74c945f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Sundeep</media:title>
		</media:content>
	</item>
		<item>
		<title>Solutions to common ASP.NET problems</title>
		<link>http://stweet.wordpress.com/2011/04/13/solutions-to-common-asp-net-problems/</link>
		<comments>http://stweet.wordpress.com/2011/04/13/solutions-to-common-asp-net-problems/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 21:19:33 +0000</pubDate>
		<dc:creator>Sundeep Podugu</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://stweet.wordpress.com/2011/04/13/solutions-to-common-asp-net-problems/</guid>
		<description><![CDATA[Being an active participant in asp.net web forums, most of the time I see some common issues being raised by the developers. Some issues are within the ASP.NET (may or may not be documented) and some are just misconceptions. This post covers few among these issues based upon my experience. Fileupload control in ASP.NET AJAX [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=303&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Being an active participant in <a href="http://forums.asp.net" target="_blank">asp.net web forums</a>, most of the time I see some common issues being raised by the developers. Some issues are within the ASP.NET (may or may not be documented) and some are just misconceptions. This post covers few among these issues based upon my experience.<br />
</p>
<ol>
<li><strong>Fileupload control in ASP.NET AJAX Update panel</strong>
<p>Fileupload control doesn&#8217;t work in ASP.NET AJAX Update panel. Though it seems to work using synchronous postback trigger but it does full postback of the page. Instead use ASP<a href="http://www.asp.net/ajax/ajaxcontroltoolkit/samples/asyncfileupload/asyncfileupload.aspx" target="_blank">.NET AJAX AsyncFileUpload control</a> introduced in ASP.NET AJAX 3.5 which uploads the file through partial post back.&nbsp;</p>
<p>Also there are other free 3<sup>rd</sup> party controls available like <a href="http://swfupload.org/" target="_blank">swf upload</a>, <a target="_blank" href="http://neatupload.codeplex.com/">neat upload</a>, etc.,   which displays status of the upload process and also asynchronously upload the file.</li>
<li> <strong>Preventing duplicate insertion on page refresh or fire postback events twice on page refresh</strong>
<p>Consider a page through which a new record like a new customer is inserted into the database. Assuming the page is working fine i.e., upon clicking the submit button, a new record with the entered values is created in the database. Now, accidentally clicking refresh button will insert a new record in the database with same values hence duplicating the record but with new different &#8220;CustomerId&#8221;.&nbsp;</p>
<p>For this problem there are various solutions like redirecting to other page or to the same page upon clicking on the submit button. Thanks to <a href="http://aspalliance.com/687_Preventing_Duplicate_Record_Insertion_on_Page_Refresh.all" target="_blank">Terry Morton</a>, she has posted an article which covers <a href="http://aspalliance.com/687_Preventing_Duplicate_Record_Insertion_on_Page_Refresh.all" target="_blank">this topic</a> in depth.</li>
<li> <strong>Page is getting showed up even after logout</strong>
<p>Suppose forms authentication is implemented in a web application and authenticated user is able to login into the application. While signing out, the session and authentication cookie are cleared using Session.Abadon() and FormsAuthentication.Signout() methods and user is successfully redirected to login page or home page.&nbsp;</p>
<p>Now, when any anonymous user hits browser &#8220;back button&#8221;, again the previous page from which authenticated user signed out is visible but when some action is performed on the page like clicking a button or link on the page, it redirects them back to login page or home page. Though there is no harm but it&#8217;s not secure and is considered as bug in the application.</p>
<p>Along with clearing session and authentication cookie, cache must be cleared. Check out the solutions given by <a href="http://forums.asp.net/t/1449206.aspx" target="_blank">Hajan</a> and other developers in <a href="http://forums.asp.net/t/1449206.aspx" target="_blank">this thread</a>.</li>
<li> <strong>Roles attribute in each node in ASP.NET sitemap control</strong>
<p>Site node in the sitemap control which has &#8220;Roles&#8221; attribute makes us think it restricts the visibility of the node for the specified roles. Most of developers have mistaken its functionality. It is indeed reverse of it, the site map node shows up for those roles specified. Restriction is actually controlled by authorization but not through the attributes. Check out Dave Sussman&#8217;s <a target="_blank" href="http://aspadvice.com/blogs/dsussman/archive/2004/10/16/2268.aspx">article</a> for detailed explanation regarding this and also <a target="_blank" href="http://stweet.wordpress.com/2010/06/13/designing-the-folder-structure-of-the-asp-net-web-application/">my article</a> which covered some of its detail by implementing it practically.&nbsp;</p>
<p>Hope you liked the post, please comment similar kind of issues to update the list. Happy coding <span style="font-family:Wingdings;">J</span></li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stweet.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stweet.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stweet.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stweet.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stweet.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stweet.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stweet.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stweet.wordpress.com/303/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=303&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stweet.wordpress.com/2011/04/13/solutions-to-common-asp-net-problems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/407a17e18d46593d3acfda3ad74c945f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Sundeep</media:title>
		</media:content>
	</item>
		<item>
		<title>Designing sequential workflow database for business applications</title>
		<link>http://stweet.wordpress.com/2011/04/09/designing-sequential-workflow-database-for-business-applications/</link>
		<comments>http://stweet.wordpress.com/2011/04/09/designing-sequential-workflow-database-for-business-applications/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 21:40:46 +0000</pubDate>
		<dc:creator>Sundeep Podugu</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Workflow Database]]></category>

		<guid isPermaLink="false">http://stweet.wordpress.com/2011/04/09/designing-sequential-workflow-database-for-business-applications/</guid>
		<description><![CDATA[Overview This article describes about an approach to design database for the objects which have sequential workflow in an application. Description In most of the business applications, we come across certain items which have a workflow defined in the system. For example, in e-commerce applications, orders have a workflow starting from placing the order till [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=280&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Overview<br />
</strong></p>
<p>This article describes about an approach to design database for the objects which have sequential workflow in an application.</p>
<p><strong>Description<br />
</strong></p>
<p>In most of the business applications, we come across certain items which have a workflow defined in the system. For example, in e-commerce applications, orders have a workflow starting from placing the order till the items getting shipped. The stages or the workflow of the object is defined by the business of the application. Workflows drive the system. So it is very important to have a flexible application to maintain the workflows. In this article, I tried to come up with the database design to manage such workflows.</p>
<p>We will define a simple workflow for orders and walk through the design process.</p>
<p><img src="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse11.jpg?w=575" alt="" /></p>
<p>As the image infers the order workflow begins when a customer orders an item, then it gets processed and finally shipped.</p>
<p><strong>Implementation<br />
</strong></p>
<p>Starting with &#8220;Orders&#8221; table, we can think of columns such as OrderId, CustomerId, CreatedDate, Status.</p>
<p>OrderId – Auto numbering column distinctly identify the orders</p>
<p>CustomerId – Identifies the customer who placed the order</p>
<p>CreatedDate &#8211; Date on which order is placed</p>
<p><strong>Status – </strong>To maintain the current status of the order such as ordered, processed, shipped</p>
<p>We are now bothered about the &#8220;<strong>status&#8221;</strong> column in the &#8220;Orders&#8221; table which manages the workflow. As a novice developer, I tend to think of storing state of the order directly into the status column (varchar) like &#8216;ordered&#8217;, &#8220;processed&#8221; and &#8216;shipped&#8217; which is a bad idea because somewhere we need to hard code the workflow (may be in stored procedure or in front end). For instance, maybe we need to check the current status of an order by using &#8216;if-loop&#8217; and then hard code the next step.</p>
<p><img src="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse21.jpg?w=575" alt="" /></p>
<p>To overcome it, we can plan to store an integer value in the status column and uniquely identify each state like 1-Ordered, 2-Processed, 3-Shipped. So whenever item moves to next stage current status is increased by 1. Going by first glance, it seems good. But we are again hard coding things, I mean how does a new developer know that 1 is for Ordered, 2 is for Processed and 3 is for Shipped. It is better we maintain another table namely &#8220;Status&#8221; with &#8220;StatusId&#8221; (Primary key) and &#8220;Name&#8221; columns. And we refer &#8220;StatusId&#8221; column in the &#8220;Orders&#8221; table as foreign key. Suppose an order which is under processing is having status &#8217;2&#8242; and when it&#8217;s ready to ship, the status is incremented by &#8217;1&#8242; and status changes to &#8217;3&#8242;. Ok done and all seems to be working well and solution is deployed.</p>
<p><img src="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse31.jpg?w=575" alt="" /></p>
<p>One fine day, client wants to improve the efficiency of the system by introducing an additional state &#8216;Review&#8217; before processing the order. Now the workflow of the order is changed to <strong>Ordered &gt; Review &gt; Processed &gt; Shipped</strong>. Assuming that quite a number of orders are already in the database, will the above modification in the workflow fit in the existing database design? Let&#8217;s check it.</p>
<p><img src="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse41.jpg?w=575" alt="" /></p>
<p>We can&#8217;t re-order the workflow by directly changing the &#8220;processed&#8221; status to &#8220;review&#8221; and altering the statusid of &#8220;processed&#8221; state to 3 and shipped to 4 since some orders already exists with processed or shipped status. Changing likewise will bring all shipped items to processed and processed items to review which isn&#8217;t good.</p>
<p>So we consider adding the new &#8220;review&#8221; status with status id as 4. Now after ordered (statusid = 1) it should be review (statusid = 4) not processed, so the above logic doesn&#8217;t work as we are incrementing the statusid each time the order state is changed. And again for that we need to hardcode the workflow in the stored procedure or front end to incorporate the modification.</p>
<p>Database has to be designed in such a manner that any modification like adding a new state or removal of existing state from the workflow can be easily done and shouldn&#8217;t impact the existing system. For that we add &#8220;NextStatusId&#8221; column to the &#8220;Status&#8221; table. &#8220;NextStatusId&#8221; column stores the &#8220;statusid&#8221; of the next state in the workflow.  Below are their values for the above defined scenario.</p>
<p><img src="http://stweet.files.wordpress.com/2011/04/orders3.jpg?w=575" alt="" /></p>
<p>By this database modification, the orders which are already having &#8220;Ordered&#8221; status will pick next state from &#8220;NextStatusId&#8221; column and will move to &#8220;Review&#8221; and from &#8220;Review&#8221; they move to &#8220;Processed&#8221; following the modified workflow. Whenever a new state is added or removed the &#8220;NextStatusId&#8221; ” of the affected states are altered accordingly.</p>
<p>It works well with the business applications which have sequential workflow defined through a certain <strong>single</strong> path. How about designing the database for the applications which have many alternative flows in each state or having the options to switch from current state to other states. Stay tuned!</p>
<p>I would like to thank my ex-colleague <strong>Sumanth Pereji</strong> for reviewing the concept.</p>
<p>Please feel free to comment with alternative ideas or criticize the presented one.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stweet.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stweet.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stweet.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stweet.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stweet.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stweet.wordpress.com/280/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stweet.wordpress.com/280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stweet.wordpress.com/280/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=280&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stweet.wordpress.com/2011/04/09/designing-sequential-workflow-database-for-business-applications/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/407a17e18d46593d3acfda3ad74c945f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Sundeep</media:title>
		</media:content>

		<media:content url="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse11.jpg" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse21.jpg" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse31.jpg" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2011/04/040811_2303_designingse41.jpg" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2011/04/orders3.jpg" medium="image" />
	</item>
		<item>
		<title>Designing the folder structure of the ASP.NET web application</title>
		<link>http://stweet.wordpress.com/2010/06/13/designing-the-folder-structure-of-the-asp-net-web-application/</link>
		<comments>http://stweet.wordpress.com/2010/06/13/designing-the-folder-structure-of-the-asp-net-web-application/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 11:09:54 +0000</pubDate>
		<dc:creator>Sundeep Podugu</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SiteMap]]></category>

		<guid isPermaLink="false">http://stweet.wordpress.com/2010/06/13/designing-the-folder-structure-of-the-asp-net-web-application/</guid>
		<description><![CDATA[Overview This article describes a way to design the folder structure of ASP.NET web application and utilize the default features provided by ASP.NET framework. Description Sometime ago I was working on a small web application which had limited business functionality. Below are the main points which had to be considered before starting with the coding. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=216&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Verdana;font-size:8pt;"><strong>Overview<br />
</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">This article describes a way to design the folder structure of ASP.NET web application and utilize the default features provided by ASP.NET framework.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Description<br />
</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Sometime ago I was working on a small web application which had limited business functionality. Below are the main points which had to be considered before starting with the coding.<br />
</span></p>
<ol>
<li><span style="font-family:Verdana;font-size:8pt;">Application is accessed by only 3 types of users i.e., Anonymous Users, Authenticated/Registered Users and Administrators. User should be able to access their respective pages, without any hard coding to check the roles in individual pages.<br />
</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Since the scope of the application is minimal, implementing complex things like roles provider to check the role of logged-in user is not preferable</span><span style="font-family:Verdana;font-size:8pt;"> and application should be able to manage it.<br />
</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Menu should automatically pickup and display the pages which user can access based upon his privileges.<br />
</span></li>
</ol>
<p><span style="font-family:Verdana;font-size:8pt;">This article mainly describes features in ASP.NET to meet the above requirements with ease.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Implementation:<br />
</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Prior to start with the actual thing, I assume that authentication (Forms\Windows) is already implemented in the web application. This application uses forms authentication and if you&#8217;re interested to know more about forms authentication, check <a target="_blank" href="http://www.asp.net/security/tutorials/an-overview-of-forms-authentication-vb">1</a> &amp; <a target="_blank" href="http://msdn.microsoft.com/en-us/library/ff647070.aspx">2</a> for detailed explanation and click <a target="_blank" href="http://support.microsoft.com/kb/301240">here</a> for simple straight forward approach.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Let us start with implementation now.<br />
</span></p>
<ol>
<li><span style="font-family:Verdana;font-size:8pt;">Below is the initial solution of the application.<br />
</span></li>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth11.png?w=575" alt="" /></p>
<li><span style="font-family:Verdana;font-size:8pt;">Pages marked in &#8220;green&#8221; should be visible to all users (Anonymous users), &#8220;blue&#8221; should be visible to Authenticated/Registered users and &#8220;red&#8221; should be visible to &#8220;Administrators&#8221; as shown below.<br />
</span></li>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth21.png?w=575" alt="" /></p>
<p><span style="font-family:Verdana;font-size:8pt;">Application uses forms authentication and for simplicity users are hardcoded in &#8220;web.config&#8221; file so that I can easily login and demo the features discussed in this article.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"> </span></p>
<p><pre class="brush: xml;">
  &lt;authentication mode=&quot;Forms&quot;&gt;
      &lt;forms name=&quot;.rexo&quot; loginUrl=&quot;home.aspx&quot; protection=&quot;All&quot;  defaultUrl=&quot;~/user/contacts.aspx&quot;&gt;
        &lt;credentials passwordFormat=&quot;Clear&quot;&gt;
          &lt;!--Registered users--&gt;
          &lt;user name=&quot;tom&quot; password=&quot;tom&quot;/&gt;
          &lt;user name=&quot;jerry&quot; password=&quot;jerry&quot;/&gt;
          &lt;!--Admin user--&gt;
          &lt;user name=&quot;admin1&quot; password=&quot;admin1&quot;/&gt;
          &lt;user name=&quot;admin2&quot; password=&quot;admin2&quot;/&gt;
        &lt;/credentials&gt;
      &lt;/forms&gt;
&lt;/authentication&gt;
</pre></p>
<li> <span style="font-family:Verdana;font-size:8pt;">Our first aim is to restrict the web pages based upon their roles i.e., set authorization to the pages. For that, create a new folder &#8220;User&#8221; in the solution and place all the pages which can only be accessed by authenticated users of the application. </span></li>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth31.png?w=575" alt="" /></p>
<li><span style="font-family:Verdana;font-size:8pt;">Navigate to &#8220;web.config&#8221; file, set the authorization using &#8220;&lt;location&gt;&#8221; tag which restricts the anonymous users to access pages placed in &#8220;User&#8221; folder.<br />
</span></li>
<p><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<p><pre class="brush: xml;">
&lt;configuration&gt;
  &lt;appSettings/&gt;
  &lt;connectionStrings/&gt;
  &lt;system.web&gt;
    &lt;compilation debug=&quot;false&quot;&gt;
    &lt;/compilation&gt;
&lt;authentication mode=&quot;Forms&quot;&gt;
      &lt;forms name=&quot;.rexo&quot; loginUrl=&quot;home.aspx&quot; protection=&quot;All&quot; defaultUrl=&quot;default.aspx&quot;&gt;
        &lt;credentials passwordFormat=&quot;Clear&quot;&gt;
          &lt;!--Registered users--&gt;
          &lt;user name=&quot;tom&quot; password=&quot;tom&quot; /&gt;
          &lt;user name=&quot;jerry&quot; password=&quot;jerry&quot; /&gt;
          &lt;!--Admin users--&gt;
          &lt;user name=&quot;admin1&quot; password=&quot;admin1&quot; /&gt;
          &lt;user name=&quot;admin2&quot; password=&quot;admin2&quot; /&gt;
        &lt;/credentials&gt;
      &lt;/forms&gt;
    &lt;/authentication&gt;  &lt;/system.web&gt;
&lt;!--This tag restricts the unauthenticated users to access pages placed in user folder --&gt;
  &lt;location path=&quot;User&quot;&gt;
    &lt;system.web&gt;
      &lt;authorization&gt;
        &lt;deny users=&quot;?&quot;/&gt;
      &lt;/authorization&gt;
    &lt;/system.web&gt;
  &lt;/location&gt;
&lt;/configuration&gt;

</pre></p>
<p><span style="font-family:Verdana;font-size:8pt;">If it is messing-up root &#8220;web.config&#8221; file, add a new &#8220;web.config&#8221; file in &#8220;User&#8221; folder and directly write the authorization tag inside &#8220;&lt;system.web&gt;&#8221; section without specifying &#8220;&lt;location&gt;&#8221; tag.<br />
</span></p>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth41.png?w=575" alt="" /></p>
<li><span style="font-family:Verdana;font-size:8pt;">Now without logging into the application, try to access any page placed in &#8220;User&#8221; folder like &#8220;emails.aspx&#8221;. It&#8217;ll be redirected to login page with url of the page which is accessed being stored in &#8220;ReturnUrl&#8221; parameter of the querystring.<br />
</span><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth51.png?w=575" alt="" /></li>
<p><span style="font-family:Verdana;font-size:8pt;">And when username and password is typed, user gets navigated directly to emails page.<br />
</span></p>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth61.png?w=575" alt="" /></p>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth71.png?w=575" alt="" /><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<li> <span style="font-family:Verdana;font-size:8pt;">Moving forward with our requirements, we don&#8217;t want all the registered users to be able to access &#8220;AdminTasks&#8221; and &#8220;Userslist&#8221; pages. Only &#8220;Administrators&#8221; needs to have access to these pages. This can also be done through configuration without implementing role manager. For that, we need to create another folder &#8220;Admin&#8221;, place the admin related pages in that and specify the authorization tag in the &#8220;web.config&#8221; file as below.<br />
</span></li>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth81.png?w=575" alt="" /></p>
<p><span style="font-family:Verdana;font-size:8pt;">This can also be achieved without creating a &#8220;web.config&#8221; file separately, by defining the authorization via &lt;location&gt; tag in root &#8220;web.config&#8221; file as we have done before for &#8220;User&#8221; folder. But for easy understanding, I chose this way.<br />
</span></p>
<li>
<div><span style="font-family:Verdana;font-size:8pt;">Next thing is to have a &#8220;menu&#8221; control which displays appropriate menu items for respective user. I mean if anonymous user is browsing the application, he should be able to see &#8220;Home&#8221;, &#8220;Feedback&#8221; &amp; &#8220;AboutUs&#8221; pages and registered users should see &#8220;Contacts&#8221; &amp; &#8220;Emails&#8221; pages and administrator should be able to see &#8220;Admintasks&#8221; &amp; &#8220;Userslist&#8221; pages. Below is the sitemap file<br />
</span></div>
<p><span style="font-family:Verdana;font-size:8pt;"> </span></p>
<p><pre class="brush: xml;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;siteMap xmlns=&quot;http://schemas.microsoft.com/AspNet/SiteMap-File-1.0&quot; &gt;
    &lt;siteMapNode url=&quot;default.aspx&quot; title=&quot;&quot;  description=&quot;&quot;&gt;
      &lt;!--Anonymous users--&gt;
        &lt;siteMapNode url=&quot;Home.aspx&quot; title=&quot;Home&quot;  description=&quot;&quot; /&gt;
        &lt;siteMapNode url=&quot;AboutUs.aspx&quot; title=&quot;About Us&quot;  description=&quot;&quot; /&gt;
        &lt;siteMapNode url=&quot;Feedback.aspx&quot; title=&quot;Feedback&quot;  description=&quot;&quot; /&gt;
      &lt;!--Registered users--&gt;
      &lt;siteMapNode url=&quot;user/contacts.aspx&quot; title=&quot;Contacts&quot;  description=&quot;&quot; /&gt;
      &lt;siteMapNode url=&quot;user/emails.aspx&quot; title=&quot;Emails&quot;  description=&quot;&quot; /&gt;
      &lt;!--Admin pages--&gt;
      &lt;siteMapNode url=&quot;admin/admintasks.aspx&quot; title=&quot;Admin tasks&quot;  description=&quot;&quot; /&gt;
      &lt;siteMapNode url=&quot;admin/userslist.aspx&quot; title=&quot;Users List&quot;  description=&quot;&quot; /&gt;
    &lt;/siteMapNode&gt;
&lt;/siteMap&gt;
</pre></p>
<p><span style="font-family:Verdana;font-size:8pt;">Before we go further, we&#8217;ll just browse the attributes of sitemap node. We can see &#8220;securityTrimmingEnabled&#8221; and &#8220;Roles&#8221; attribute which makes us think that if Security Trimming is set to &#8220;true&#8221; and by specifying list of roles in &#8220;roles&#8221; attributes, we are done with the task. But wait, we don&#8217;t have role manager implemented in the application which restricts us to use default features of sitemap control.<br />
</span></p>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth9.png?w=575" alt="" /><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong><em>All our assumptions are wrong!!</em></strong> I must say almost 99% of newbies of sitemap control will fall prey to this misconception. &#8220;Roles&#8221; attribute will make the sitemap node to show up for the specified roles instead of restricting the users.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">So how to restrict the menu items based on the roles of the user. In fact, we need not do anything to achieve the functionality. Sitemap control automatically picks up the authorization tags specified in &#8220;web.config&#8221; file and displays the menu items for the respective user.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">In root web.config, specify the sitemap provider and set &#8220;securityTrimmingEnabled&#8221; to true which is false by default.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<p><pre class="brush: xml;">
  &lt;siteMap defaultProvider=&quot;myprovider&quot; enabled=&quot;true&quot;&gt;
      &lt;providers&gt;
        &lt;add name=&quot;myprovider&quot; type=&quot;System.Web.XmlSiteMapProvider &quot; siteMapFile=&quot;web.sitemap&quot; securityTrimmingEnabled=&quot;true&quot;/&gt;
      &lt;/providers&gt;
    &lt;/siteMap&gt;
</pre></p>
<p><span style="font-family:Verdana;font-size:8pt;">Menu control is usually placed in a master page and set &#8220;datasourceid&#8221; property of menu control to sitemapdatasource.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<p><pre class="brush: xml;">
&lt;asp:Menu ID=&quot;rexoMenu&quot; runat=&quot;server&quot; DataSourceID=&quot;SiteMapDataSource1&quot; CssClass=&quot;menu2&quot;
                    Orientation=&quot;Horizontal&quot;&gt;
                    &lt;LevelMenuItemStyles&gt;
                        &lt;asp:MenuItemStyle CssClass=&quot;menu2&quot; /&gt;
                    &lt;/LevelMenuItemStyles&gt;
 &lt;/asp:Menu&gt;
&lt;asp:SiteMapDataSource ID=&quot;SiteMapDataSource1&quot; runat=&quot;server&quot; ShowStartingNode=&quot;false&quot;  StartingNodeOffset=&quot;0&quot;/&gt;
</pre></p>
<p><span style="font-family:Verdana;font-size:8pt;">For more details regarding sitemap control and authorization tags check out Dave Sussman&#8217;s <a target="_blank" href="http://aspadvice.com/blogs/dsussman/archive/2004/10/16/2268.aspx">article</a>.<br />
</span></li>
</ol>
<p><span style="font-family:Verdana;font-size:8pt;">Now let us browse the application.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Logged-in as registered user – (tom)<br />
</strong></span></p>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth10.png?w=575" alt="" /><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Logged-in as administrator – (admin1)<br />
</strong></span></p>
<p><img src="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth111.png?w=575" alt="" /><span style="font-family:Verdana;font-size:8pt;"><br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">That&#8217;s it. I guess we are done with the requirements and good to start with coding. Happy Coding!!</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Note: The concepts described in this article also work with Windows Authentication. And it applies to both ASP.NET website and web application project.</strong><br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Conclusion</strong><br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">This article described some of the features in ASP.NET framework to be considered while designing the folder structure of the application. <strong><br />
</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><em>I would like to thank everyone for encouraging me through your comments and mails for my <a title="Creating a new website programmatically on IIS using ASP.NET and C#" href="http://stweet.wordpress.com/2010/03/15/creating-a-new-website-programmatically-on-iis-using-asp-net/" target="_self">first article</a>. I am also glad that it has been published as article of the day on asp.net website.<br />
</em></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stweet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stweet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stweet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stweet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stweet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stweet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stweet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stweet.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=216&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stweet.wordpress.com/2010/06/13/designing-the-folder-structure-of-the-asp-net-web-application/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/407a17e18d46593d3acfda3ad74c945f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Sundeep</media:title>
		</media:content>

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth11.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth21.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth31.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth41.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth51.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth61.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth71.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth81.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth9.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth10.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/06/061310_1108_designingth111.png" medium="image" />
	</item>
		<item>
		<title>Creating a new website programmatically on IIS using ASP.NET and C#</title>
		<link>http://stweet.wordpress.com/2010/03/15/creating-a-new-website-programmatically-on-iis-using-asp-net/</link>
		<comments>http://stweet.wordpress.com/2010/03/15/creating-a-new-website-programmatically-on-iis-using-asp-net/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 20:46:26 +0000</pubDate>
		<dc:creator>Sundeep Podugu</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://stweet.wordpress.com/2010/03/15/creation-of-new-web-site-programmatically-on-iis-6-0-using-asp-net/</guid>
		<description><![CDATA[Overview This article describes how to create a new web site on IIS using ASP.NET and C#. Description Before going into the article, I just want to brief about the client requirement. Our web application is Content Management System which allows users to create new websites and host it on the server. Users can browse [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=7&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Verdana;font-size:8pt;"><strong>Overview<br />
</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">This article describes how to create a new web site on IIS using ASP.NET and C#.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Description<br />
</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Before going into the article, I just want to brief about the client requirement.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Our web application is Content Management System which allows users to create new websites and host it on the server. Users can browse through the available domain names via a third party API and select a domain name and choose to host it on the server and then a new ASP.NET website should be created on IIS automatically and run within no time.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">For each new website request, administrator cannot open IIS to create a new ASP.NET website. We require an instant solution where user enters website name and a new website should be created automatically on IIS with required settings like host name, local path, default document, etc., similar to the settings which a user does manually through wizard on the server.<br />
</span></p>
<p style="text-align:center;"><img src="http://stweet.files.wordpress.com/2010/03/031510_2045_creationofn135.png?w=575" alt="" /></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Environment: </strong>Windows Server 2003, IIS 6.0, ASP.NET 2.0</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">For demo purposes, user interface is .aspx page with just a text box to enter website name and a submit button.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">On the server side, web service does the job. It takes the website name as parameter and creates new website on IIS.<br />
</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">And a point to be noted is all the new websites created point to a same physical location and depending upon the name of the website, content gets populated. If you need to configure different physical paths for each website, send an additional parameter to the web service. </span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Let&#8217;s start the job now<br />
</span></p>
<ol>
<li><span style="font-family:Verdana;font-size:8pt;">Create a new &#8220;ASP.NET Web Service&#8221; with Language as &#8220;C#&#8221;.<br />
</span></li>
<li>
<div><span style="font-family:Verdana;font-size:8pt;">Open &#8220;web.config&#8221; file, add below configuration values under &#8220;appSettings&#8221; section.<br />
</span></div>
<p><span style="font-family:Verdana;font-size:8pt;"><pre class="brush: xml;">
&lt;appSettings&gt;
  &lt;clear/&gt;
  &lt;!---Default format is IIS://&lt;your server name&gt;/W3SVC--&gt;
  &lt;add key=&quot;metabasePath&quot; value=&quot;IIS://C37336-113134/W3SVC&quot;/&gt;
  &lt;!--Framework version of newly created website--&gt;
  &lt;add key=&quot;frameworkVersion&quot; value=&quot;2.0.50727&quot;/&gt;
  &lt;!---Local path of newly created website --&gt;
  &lt;add key=&quot;defaultFileLocation&quot; value=&quot;C:\Test&quot;/&gt;
  &lt;!---Application Pool of newly created website--&gt;
  &lt;add key=&quot;defaultAppPool&quot; value=&quot;CustomAppPool&quot;/&gt;
&lt;/appSettings&gt;</pre></p>
<p>&nbsp;</p>
<p></span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Add Reference to &#8220;System.DirectoryServices&#8221; library and navigate to .cs file and import the namespaces &#8220;using System.DirectoryServices&#8221;.<br />
</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Write a new web method &#8220;CreateWebsite</span><span style="font-family:Courier New;font-size:10pt;">&#8220;</span></li>
<p><pre class="brush: csharp;">/// &lt;summary&gt;
/// Creates new ASP.NET website on IIS
/// &lt;/summary&gt;
/// &lt;param name=&quot;siteName&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
[WebMethod]
public string CreateWebsite(string siteName)
{
  try
  {
     //Initialize configuration variables
     string metabasePath =  Convert.ToString(ConfigurationManager.AppSettings[&quot;metabasePath&quot;]);
     string frameworkVersion = Convert.ToString(ConfigurationManager.AppSettings[&quot;frameworkVersion&quot;].ToString());
     string physicalPath = Convert.ToString(ConfigurationManager.AppSettings[&quot;defaultFileLocation&quot;].ToString());
     string defaultAppPool = ConfigurationManager.AppSettings[&quot;defaultAppPool&quot;].ToString();//Host Header Info
     object[] hosts = new object[2];
     string hostHeader = siteName.Replace(&quot;www.&quot;, string.Empty).Replace(&quot;.com&quot;,string.Empty);
     hosts[0] = &quot;:80:&quot; + hostHeader+&quot;.com&quot;;
     hosts[1] = &quot;:80:&quot; + &quot;www.&quot; + hostHeader + &quot;.com&quot;;

     //Gets unique site id for the new website
     int siteId = GetUniqueSiteId(metabasePath);

     //Extracts the directory entry
     DirectoryEntry objDirEntry = new DirectoryEntry(metabasePath);
     string className = objDirEntry.SchemaClassName;
     if (!className.EndsWith(&quot;Service&quot;)) return &quot;Invalid configuration variables&quot;;

     //creates new website by specifying site name and host header
     DirectoryEntry newSite = objDirEntry.Children.Add(Convert.ToString(siteId), (className.Replace(&quot;Service&quot;, &quot;Server&quot;)));
     newSite.Properties[&quot;ServerComment&quot;][0] = siteName;
     newSite.Properties[&quot;ServerBindings&quot;].Value = hosts;
     newSite.Invoke(&quot;Put&quot;, &quot;ServerAutoStart&quot;, 1);
     newSite.Invoke(&quot;Put&quot;, &quot;ServerSize&quot;, 1);
     newSite.CommitChanges();

     //Creates root directory by specifying the local path, default  document and permissions
     DirectoryEntry newSiteVDir = newSite.Children.Add(&quot;Root&quot;, &quot;IIsWebVirtualDir&quot;);
     newSiteVDir.Properties[&quot;Path&quot;][0] = physicalPath;
     newSiteVDir.Properties[&quot;EnableDefaultDoc&quot;][0] = true;
     newSiteVDir.Properties[&quot;DefaultDoc&quot;].Value = &quot;default.aspx&quot;;
     newSiteVDir.Properties[&quot;AppIsolated&quot;][0] = 2;
     newSiteVDir.Properties[&quot;AccessRead&quot;][0] = true;
     newSiteVDir.Properties[&quot;AccessWrite&quot;][0] = false;
     newSiteVDir.Properties[&quot;AccessScript&quot;][0] = true;
     newSiteVDir.Properties[&quot;AccessFlags&quot;].Value = 513;
     newSiteVDir.Properties[&quot;AppRoot&quot;][0] = @&quot;/LM/W3SVC/&quot; + Convert.ToString(siteId) + &quot;/Root&quot;;
     newSiteVDir.Properties[&quot;AppPoolId&quot;].Value = defaultAppPool;
     newSiteVDir.Properties[&quot;AuthNTLM&quot;][0] = true;
     newSiteVDir.Properties[&quot;AuthAnonymous&quot;][0] = true;
     newSiteVDir.CommitChanges();

     //Sets the framework version to 2.0 for the new website
     //Assuming the version will be something like n.n.nnnnn
     Regex versionRegex = new Regex(@&quot;(?&lt;=\\v)\d{1}\.\d{1}\.\d{1,5}(?=\\)&quot;);
     PropertyValueCollection lstScriptMaps =  newSiteVDir.Properties[&quot;ScriptMaps&quot;];
     System.Collections.ArrayList arrScriptMaps = new   System.Collections.ArrayList();
      foreach (string scriptMap in lstScriptMaps)
      {
          if (scriptMap.Contains(&quot;Framework&quot;))
          {
             arrScriptMaps.Add(versionRegex.Replace(scriptMap, frameworkVersion));
          }
          else
         {
             arrScriptMaps.Add(scriptMap);
          }
       }
      newSiteVDir.Properties[&quot;ScriptMaps&quot;].Value =  arrScriptMaps.ToArray();
      newSiteVDir.CommitChanges();
      return &quot;Website created successfully.&quot;;
  }
  catch (Exception ex)
  {
      return &quot;Website creation failed. &lt;br/&gt;&quot; + ex.Message;
  }
}

/// &lt;summary&gt;
/// Retunrs Unique SiteId for the new website
/// &lt;/summary&gt;
/// &lt;param name=&quot;metabasePath&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private int GetUniqueSiteId(string metabasePath)
{
     int siteId = 1;
     DirectoryEntry objDirEntry = new DirectoryEntry(metabasePath);
     foreach (DirectoryEntry e in objDirEntry.Children)
     {
        if (e.SchemaClassName == &quot;IIsWebServer&quot;)
        {
            int id = Convert.ToInt32(e.Name);
            if (id &gt;= siteId)
            siteId = id + 1;
         }
      }
     return siteId;
}
</pre></p>
<li><span style="font-family:Verdana;font-size:8pt;">Now take a new &#8220;ASP.NET website&#8221; and add the web reference to the created web service.</span><span style="font-family:Verdana;font-size:8pt;"><br />
</span></li>
<li><span style="font-family:Verdana;font-size:8pt;"> In default.aspx, place a textbox control and button control and in button click event handler, call the web method by passing in textbox value.</span><br />
<pre class="brush: csharp;">
Service createWebsiteService = new Service();
lblStatus.Text = createWebsiteService.CreateWebsite(txtSiteName.Text);
</pre></li>
<li><span style="font-family:Verdana;font-size:8pt;"> Now get ready to run the application and enter a website name &#8220;www.stweet.com&#8221; in the textbox and click the button.  OOPsssss!!!!</span></li>
<p><span style="font-family:Verdana;font-size:8pt;"><span style="color:red;">Access is denied. (Exception from HRESULT: 0&#215;80070005 (E_ACCESSDENIED))</span><br />
</span></p>
<p style="text-align:center;"><img src="http://stweet.files.wordpress.com/2010/03/result.jpg?w=575" alt="" /></p>
<p><span style="font-family:Verdana;font-size:8pt;"> Don&#8217;t worry. We are not yet done with required configuration part yet.</span></ol>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Configuration</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Basically for creating a new website on IIS, user requires administrator privileges. But by default ASP.NET application runs under low privileged account i.e., Network Service, so additional settings needs to be done to run the above mentioned code.</span></p>
<p><span style="text-decoration:underline;"><span style="font-family:Verdana;font-size:8pt;"><strong>Method 1</strong></span></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Remember, we have used two ASP.NET applications for this, one for website and another for web service. Now web service needs to be run under administrative privileges. Add below code in the “web.config” file under &#8220;system.web&#8221; section.</span></p>
<p><pre class="brush: xml;">
&lt;identity impersonate=&quot;true&quot; userName=&quot;adminname&quot; password=&quot;adminpwd&quot;/&gt;
</pre></p>
<p><span style="font-family:Verdana;font-size:8pt;">It impersonates the user request with administrator privileges and thus executes the code successfully. </span></p>
<p><span style="text-decoration:underline;"><span style="font-family:Verdana;font-size:8pt;"><strong>Method 2</strong></span></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">Typing administrator user name and password in web.config may not be feasible and less secured. No problem! We can do it in other way by creating a new application pool for the web service as explained below.<br />
</span></p>
<ol>
<li><span style="font-family:Verdana;font-size:8pt;">Open IIS</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Right click on Application Pool &gt; select “New” &gt; select “Application Pool”</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Enter &#8220;Application Pool ID&#8221; and click OK. New application pool is created</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Right click on newly created application pool &gt; select “Properties”</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Navigate to “Identity” tab, choose “configurable” and enter administrator user name and password and click “OK”</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">Now configure web service to run under newly created application pool. Right click on already created web service&gt;&gt;Select “Properties” and navigate to “Home Directory” tab &gt;&gt;Select newly create application pool under “Application Pool” field</span></li>
</ol>
<p><span style="font-family:Verdana;font-size:8pt;">Note: Be careful with step no. 5 and 6, configuration issues occur while running the web service. This happens when invalid password is entered under the administrator account in application pool. In this case, modifying the administrator password doesn’t help. We need to again start configuration from beginning by removing the web service association with application domain and deleting the application domain and creating a new one with correct credentials.</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">For both methods, it is preferred to have new admin account which serves only this purpose  and make sure he is member of  <em>IIS_WPG</em> user group. Because due to security reasons, password of existing administrator may change from time to time and for every reset we need to again re-configure the application pool.</span></p>
<p><span style="font-family:Verdana;font-size:8pt;">That’s it. Now run the application and see the result.</span></p>
<p style="text-align:center;"><img src="http://stweet.files.wordpress.com/2010/03/website.jpg?w=575" alt="" /></p>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Additional Inputs</strong></span></p>
<ol>
<li><span style="font-family:Verdana;font-size:8pt;">If time is not crucial part for new website creation on IIS, consider storing the website names in a database and implement the code written in the web service in a windows application (or) windows service and schedule it, so that the configuration part can be skipped.</span></li>
<li><span style="font-family:Verdana;font-size:8pt;">On Load Balancing servers, this won&#8217;t work because we don’t know where the request is routed. In this scenario, windows application/service is preferred.</span></li>
</ol>
<p><span style="font-family:Verdana;font-size:8pt;"><strong>Conclusion</strong></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">This article demonstrated one of the concepts to create a new website on IIS programmatically using ASP.NET and C#.</span></p>
<p><span style="font-family:Verdana;font-size:8pt;"><em>Note: It is just the concept which is explained in this article but doesn’t include additional things like exception handling &amp; web service security. Please feel to modify it according to your requirements.</em></span></p>
<p><span style="font-family:Verdana;font-size:8pt;">It is my first article, please bear with me and it would be great help if you guys provide feedback and help me improve the content.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stweet.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stweet.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stweet.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stweet.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stweet.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stweet.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stweet.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stweet.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stweet.wordpress.com&amp;blog=12629651&amp;post=7&amp;subd=stweet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stweet.wordpress.com/2010/03/15/creating-a-new-website-programmatically-on-iis-using-asp-net/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/407a17e18d46593d3acfda3ad74c945f?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Sundeep</media:title>
		</media:content>

		<media:content url="http://stweet.files.wordpress.com/2010/03/031510_2045_creationofn135.png" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/03/result.jpg" medium="image" />

		<media:content url="http://stweet.files.wordpress.com/2010/03/website.jpg" medium="image" />
	</item>
	</channel>
</rss>
