<?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>PeterKellner.net &#187; Best Practices</title>
	<atom:link href="http://peterkellner.net/category/best-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focussed, JavaScript (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 03 Feb 2012 02:58:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To Safely Display Data From ASP.NET TextField Inputs</title>
		<link>http://peterkellner.net/2011/10/16/how-to-safely-display-data-from-asp-net-textfield-inputs/</link>
		<comments>http://peterkellner.net/2011/10/16/how-to-safely-display-data-from-asp-net-textfield-inputs/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 23:35:00 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Best Practices]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/10/16/how-to-safely-display-data-from-asp-net-textfield-inputs/</guid>
		<description><![CDATA[Let’s say you have a user input field that you want the user to type data into which will be later displayed back to the user.&#160; You don’t want the user putting in their own html or other things (like javascript tags) because that could cause bad things to happen on your page.&#160;   [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s say you have a user input field that you want the user to type data into which will be later displayed back to the user.&#160; You don’t want the user putting in their own html or other things (like javascript tags) because that could cause bad things to happen on your page.&#160; </p>  <p>The easiest thing to do is to set the page attribute to not do request validation</p>  <div id="codeSnippetWrapper">&#160;</div>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="background-color: #ffff00">&lt;%@ Page Title=&quot;&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/DefaultNoColumns.master&quot; AutoEventWireup=&quot;true&quot; ValidateRequest=&quot;false&quot;<br />    CodeFile=&quot;SponsorInformationEdit.aspx.cs&quot; Inherits=&quot;SponsorInformationEdit&quot; %&gt;</span></pre>

  <br /></div>

<div id="codeSnippetWrapper">
  <br /></div>

<p>Then, store whatever the user types in the textbox including the nasty things like &lt;script …</p>

<p>When you get around to displaying the data back, simply encode it like this:</p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">LabelShortDescription.Text = HttpUtility.HtmlEncode(rec.CompanyDescriptionShort);</pre>

  <br /></div>



<p>Then, if the user put a bold tag in the html, they will get this displayed back:</p>

<p>&#160;</p>

<p><a href="http://peterkellner.net/wp/wp/wp-content/uploads/2011/10/image5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/wp/wp/wp-content/uploads/2011/10/image_thumb2.png" width="402" height="104" /></a></p>

<p>and no harm will occur.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/10/16/how-to-safely-display-data-from-asp-net-textfield-inputs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SqlAzure and a Best Practices way to deal with the Required Retries on Connections</title>
		<link>http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/</link>
		<comments>http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 22:24:44 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[SqlAzure]]></category>
		<category><![CDATA[Web.Config]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/</guid>
		<description><![CDATA[Introduction  If you’ve started using SqlAzure for your SqlServer with your Azure application, you’ve probably discovered that you get a reasonable number of connection failures.&#160; The advice from the Azure team is add retry logic to all your connections to SqlAzure. There is a long discussion posted by the Azure team here.  The [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>  <p>If you’ve started using <a href="http://msdn.microsoft.com/en-us/library/ee336279.aspx">SqlAzure</a> for your <a href="http://www.microsoft.com/sqlserver/2008/en/us/r2.aspx">SqlServer</a> with your Azure application, you’ve probably discovered that you get a reasonable number of <a href="http://msdn.microsoft.com/en-us/library/aa175395(v=sql.80).aspx">connection</a> failures.&#160; The advice from the Azure team is add retry logic to all your connections to SqlAzure. There is a long discussion posted by the Azure team <a href="http://blogs.msdn.com/b/bartr/archive/2010/06/18/sql-azure-connection-retry.aspx?utm_source=feedburner&amp;utm_medium=twitter&amp;utm_campaign=Feed%3A+Microsoft%2FMSDN-Blogs+(MSDN+Blogs)">here</a>.</p>  <p>The key paragraph states the problem as follows:</p>  <blockquote>   <p><strong>The Problem       <br /></strong>One of the things that SQL Azure does to deliver high availability is it sometimes closes <a href="http://msdn.microsoft.com/en-us/library/ee336245.aspx">connections</a>. SQL Azure does some pretty cool stuff under the covers to minimize the impact, but this is a key difference in SQL Azure development vs. SQL Server development.</p> </blockquote>  <p>Basically, what this means is that you must be able to deal with connections failing when you call SqlAzure.&#160; Something that all of probably should have been doing forever, but because most of the time SqlServer is running on your local LAN and the likelihood if a connection failing was next to zero unless something else was going terribly wrong.&#160; Certainly not something we had to do on regular basis.&#160; To emphasize that even more, most of the controls built into asp.net that open connections to sqlserver don’t even do this and that’s from Microsoft itself.</p>  <p>The solution proposed in the thread mentioned above basically has you add tons of code to everyplace you access a connection object.&#160; Personally, I don’t like that because I have hundreds if not thousands of places I open connections and inserting tens of thousands of lines of extra new untested code is a little scary.</p>  <p>So, what to do?</p>  <p>Fortunately, another team at Microsoft, known as the <a href="http://blogs.msdn.com/b/appfabriccat">Windows Server AppFabric Customer Advisory Team</a> published a general purpose solution using Extension Methods and some darn clever coding wrote a <a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx">great article and published code</a> including <a href="http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx">azure examples</a> that solves this problem very elegantly without requiring a lot of changes to your existing code base.</p>  <p>In this article I plan on giving an example and publishing a sample project that uses this code with SqlAzure to solve the connection retry problem.&#160; My goal here is not to simply restate what they published but to simply have a very simple concrete example of using their library.</p>  <span id="more-1429"></span>  <h2>Design Goal</h2>  <p>We have two goals.</p>  <ol>   <li>     <div align="left">Change as little code as possible</div>   </li>    <li>     <div align="left">Log Connection Errors when they happen With Locations</div>   </li>    <li>     <div align="left">Make sure not to trap errors that are NOT connection related such as bad column names</div>   </li> </ol>  <p align="left">&#160;</p>  <h2 align="left">Incorrect Code</h2>  <p align="left">So, this is what the original code looks like that will fail because it does not have connection retry logic:</p>  <p align="left">&#160;</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span> UsersIdFromUserNameNoConnectionRetry(<span style="color: #0000ff">string</span> userName)<br />{<br />    var retUsersId = 0;<br />    <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> sql =<br />        <span style="color: #006080">@&quot;SELECT Id FROM Users<br />            WHERE Username = @Username&quot;</span>;<br /><br />    <span style="color: #0000ff">using</span> (var sqlConnection = <span style="color: #0000ff">new</span> SqlConnection(<br />            ConfigurationManager.ConnectionStrings[<span style="color: #006080">&quot;CRStorageWebConnectionString&quot;</span>].<br />            ConnectionString))<br />    {<br />        sqlConnection.Open();<br />        <span style="color: #0000ff">using</span> (var sqlCommand = <span style="color: #0000ff">new</span> SqlCommand(sql, sqlConnection))<br />        {<br />            sqlCommand.Parameters.Add(<span style="color: #006080">&quot;@Username&quot;</span>, SqlDbType.NVarChar).Value = userName;<br />            <span style="color: #0000ff">using</span> (var reader = sqlCommand.ExecuteReader())<br />            {<br />                <span style="color: #0000ff">while</span> (reader.Read())<br />                {<br />                    retUsersId = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);<br />                }<br />            }<br />        }<br />    }<br />    <span style="color: #0000ff">return</span> retUsersId;<br />}</pre>

  <br /></div>

<p align="left">So, if there is a connection, an exception will get thrown and will need to be caught, but then the method will not have done it’s job.</p>

<p align="left">&#160;</p>

<h2 align="left">Correct Code With Retries</h2>

<p align="left">So, now take a look at the revised code after the library is setup and used.&#160; The setup is non-trivial, but you just have to do that once and then you can simply fix all your other code with very few changes.&#160; Below is the new code with connection retry logic built in.</p>

<p align="left">&#160;</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span> UsersIdFromUserName(<span style="color: #0000ff">string</span> userName)<br />{<br />    var retUsersId = 0;<br />    <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> sql =<br />        <span style="color: #006080">@&quot;SELECT Id FROM Users<br />            WHERE Username = @Username&quot;</span>;<br /><br />    <span style="color: #0000ff">using</span> (var sqlConnection =<br />        <span style="color: #0000ff">new</span> ReliableSqlConnection(<br />            ConfigurationManager.ConnectionStrings[<span style="color: #006080">&quot;CRStorageWebConnectionString&quot;</span>].<br />            ConnectionString,<br />            <span style="color: #0000ff">new</span> RetryUtils(<span style="color: #006080">&quot;&quot;</span>, <span style="color: #006080">&quot;UsersIdFromUserName&quot;</span>).GetRetryPolicy()))<br />    {<br />        sqlConnection.Open();<br />        <span style="color: #0000ff">using</span> (var sqlCommand = <span style="color: #0000ff">new</span> SqlCommand(sql, sqlConnection.Current))<br />        {<br />            sqlCommand.Parameters.Add(<span style="color: #006080">&quot;@Username&quot;</span>, SqlDbType.NVarChar).Value = userName;<br />            <span style="color: #0000ff">using</span> (var reader = sqlCommand.ExecuteReader())<br />            {<br />                <span style="color: #0000ff">while</span> (reader.Read())<br />                {<br />                    retUsersId = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);<br />                }<br />            }<br />        }<br />    }<br />    <span style="color: #0000ff">return</span> retUsersId;<br />}</pre>
</div>

<div>&#160;</div>

<div>There are basically two changes.&#160; </div>

<div>&#160;</div>

<ol>
  <li>The first is instead of create an SqlConnection(…) we are creating a ReliableSqlConnection(…).&#160; The ReliableSqlConnection takes an extra parameter which basically wraps the retry logic used, as well as labelling this connection so when it fails, it gets logged.&#160; In the log, there will be the comment “UsersIdFromUserName” so we know what method threw the retry.</li>

  <li>The second is slight change we when we create the SqlCommand, we have to add the property .Current to it so we know we are talking about the currently executing connection.&#160; There may be a default way to handle this but I could not figure it out.</li>
</ol>

<div>That’s it!&#160; you are new connection safe for retrying failed connections.</div>

<div>&#160;</div>

<h2>The Setup Pieces</h2>

<div>&#160;</div>

<div>First, download the library from the article mention above which can be found here in <a href="http://code.msdn.microsoft.com/">Microsoft’s Code Gallery</a></div>

<div>&#160;</div>

<div><a title="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;DownloadId=14007" href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;DownloadId=14007">http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=appfabriccat&amp;DownloadId=14007</a></div>

<div>&#160;</div>

<p>The project has all kinds of stuff in it that build quite nicely, run and test under vs2010.&#160; All I’m interested in is the ado.net piece and the retry logic around that.&#160; I actually used the 1.2 version, however I now see there is a 1.3 version with some improvements.&#160; I would post my project but I don’t want to post it with old code so I’ll just tell you the steps I went through so you can do the same.</p>

<h3>Build the class library</h3>

<p>Compile the project and make sure you have the dll from the library lincluded in your actual visual studio project.&#160; The library you want is Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.</p>

<p>&#160;</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/SqlAzure-and-a-Best-Practices-way-to-dea_E1CC/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/SqlAzure-and-a-Best-Practices-way-to-dea_E1CC/image_thumb.png" width="347" height="243" /></a></p>

<p>&#160;</p>

<h3>Update Your Web.config</h3>

<p>Add the config section below to your web.config file.</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">section</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;RetryPolicyConfiguration&quot;</span> <br />         <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling.Configuration.RetryPolicyConfigurationSettings,<br />            Microsoft.AppFabricCAT.Samples.Azure.TransientFaultHandling&quot;</span> <span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span><br /><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">RetryPolicyConfiguration</span> <span style="color: #ff0000">defaultPolicy</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <span style="color: #ff0000">defaultSqlConnectionPolicy</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <br />         <span style="color: #ff0000">defaultSqlCommandPolicy</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <span style="color: #ff0000">defaultStoragePolicy</span><span style="color: #0000ff">=&quot;IncrementalIntervalDefault&quot;</span> <br />         <span style="color: #ff0000">defaultCommunicationPolicy</span><span style="color: #0000ff">=&quot;IncrementalIntervalDefault&quot;</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;FixedIntervalDefault&quot;</span> <span style="color: #ff0000">maxRetryCount</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">retryInterval</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #0000ff">/&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;IncrementalIntervalDefault&quot;</span> <span style="color: #ff0000">maxRetryCount</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">retryInterval</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #ff0000">retryIncrement</span><span style="color: #0000ff">=&quot;50&quot;</span> <span style="color: #0000ff">/&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ExponentialIntervalDefault&quot;</span> <span style="color: #ff0000">maxRetryCount</span><span style="color: #0000ff">=&quot;10&quot;</span> <span style="color: #ff0000">minBackoff</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #ff0000">maxBackoff</span><span style="color: #0000ff">=&quot;1000&quot;</span> <span style="color: #ff0000">deltaBackoff</span><span style="color: #0000ff">=&quot;100&quot;</span> <span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">RetryPolicyConfiguration</span><span style="color: #0000ff">&gt;</span></pre>

  <br /></div>

<p>This defines a new section in your web.config, then implements it with several different retry policies include a default one which seems quite reasonable to me.</p>

<p>If you remember, in the implementation section above, we used a public class called RetryUtils.&#160; This class is actually one I invented as a convenience class to minimize the code I have to update on each use of the ReliableConnection Object.&#160; Just to refresh your memory, the implementation is this:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (var sqlConnection =<br />                <span style="color: #0000ff">new</span> ReliableSqlConnection(<br />                    ConfigurationManager.ConnectionStrings[<span style="color: #006080">&quot;CRStorageWebConnectionString&quot;</span>].<br />                    ConnectionString,<br />                    <span style="color: #0000ff">new</span> RetryUtils(<span style="color: #006080">&quot;&quot;</span>, <span style="color: #006080">&quot;UsersIdFromUserName&quot;</span>).GetRetryPolicy()))</pre>

  <br /></div>

<p>The actual code fo rthe class RetryUtils is below here.&#160; You’ll have to stick this someplace in your project.</p>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">namespace</span> Utils<br />{<br />   <br />    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RetryUtils<br />    {<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Username { get; set; }<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> CallersName { get; set; }<br /><br />        <span style="color: #0000ff">public</span> RetryUtils(<span style="color: #0000ff">string</span> username, <span style="color: #0000ff">string</span> callersName)<br />        {<br />            Username = username;<br />            CallersName = callersName;<br />        }<br /><br />        <span style="color: #0000ff">public</span> RetryUtils()<br />        {<br />            Username = <span style="color: #0000ff">string</span>.Empty;<br />            CallersName = <span style="color: #0000ff">string</span>.Empty;<br />        }<br /><br />        <span style="color: #0000ff">public</span> RetryPolicy&lt;SqlAzureTransientErrorDetectionStrategy&gt; GetRetryPolicy()<br />        {<br />            var retryPolicy = <span style="color: #0000ff">new</span> RetryPolicy&lt;SqlAzureTransientErrorDetectionStrategy&gt;<br />                 (RetryPolicy.DefaultClientRetryCount, RetryPolicy.DefaultMinBackoff,<br />                  RetryPolicy.DefaultMaxBackoff,<br />                  RetryPolicy.DefaultClientBackoff);<br /><br />            retryPolicy.RetryOccurred += RetryPolicyRetryOccurred;<br /><br />            <span style="color: #0000ff">return</span> retryPolicy;<br />        }<br /><br />        <span style="color: #0000ff">void</span> RetryPolicyRetryOccurred(<span style="color: #0000ff">int</span> currentRetryCount, Exception lastException, TimeSpan delay)<br />        {<br />            GeneralUtils.GetLog4NetAllDataContext().AddLog4NetAll(<span style="color: #0000ff">new</span> Log4NetAll<br />                                                    {<br />                                                        Date = DateTime.UtcNow,<br />                                                        EllapsedTime = 0,<br />                                                        ExceptionStackTrace = lastException.StackTrace,<br />                                                        Message = <span style="color: #006080">&quot;RetryCount: &quot;</span> + currentRetryCount + <span style="color: #006080">&quot; delay: &quot;</span> + delay.Seconds,<br />                                                        ExceptionMessage = lastException.Message,<br />                                                        Logger = <span style="color: #006080">&quot;&quot;</span>,<br />                                                        Level = <span style="color: #006080">&quot;Error&quot;</span>,<br />                                                        UserName = Username,<br />                                                        PartitionKey = Username,<br />                                                        RowKey = Guid.NewGuid().ToString()<br />                                                    });<br />        }       <br />    }<br />}<br /></pre>
</div>

<div>This code actually has the nice callback delegate that does the logging when a retry actually occurs.&#160; I’m not including my implementation of GeneralUtils.GetLog4NetAllDataContext().AddLog4NetAll, but you can pretty much guess what it does.&#160; It simply logs the retry with all the details of what happened.&#160; My implementation sticks this in an Azure Table, but that’s really for another post.</div>

<div>&#160;</div>

<h2>Non Connection Related Errors</h2>

<div>&#160;</div>

<div>Remember, our second design criteria is that we should only fail on errors that are connection related and not things like data column not found.&#160; With no additional work, this library takes care of this for us.&#160; Actually, in the release notes for the 1.3 release (which I have not used yet) say they have improved that feature by adding additional codes not to fail on.&#160; That is, the last thing you want is your code spending 5 minutes retrying on a problem you’d just like reported immediately. </div>

<div>&#160;</div>

<div>Keep in mind that the library we are using here is a general purpose retry library not designed just for use with ado.net.&#160; The team has provided us with examples using LINQ2SQL, EntityFramework and other technologies.&#160; I spent&#160; a little time reading about using those other technologies but did not get far enough to blog about it.&#160; My current SqlAzure implementation uses 100% ado.net because performance is critical to me and neither EF or LINQ2SQL are quite up to my task yet.</div>

<div>&#160;</div>

<h2>Conclusions</h2>

<div>&#160;</div>

<div>So basically, that’s it!&#160; You know have the tools to implement very nice retry logic in your ado.net code so Azure will not fail on “normal” connection failures.&#160; I suggest that if you are using SqlAzure, you implement this as soon as possible so your code will be solid going forward.</div>

<div>&#160;</div>

<div>Thanks for reading!</div>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>To Brace or not to Brace in C# ifs and other Constructs</title>
		<link>http://peterkellner.net/2009/10/19/codingstandards-csharp-braces/</link>
		<comments>http://peterkellner.net/2009/10/19/codingstandards-csharp-braces/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 15:24:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/10/19/codingstandards-csharp-braces/</guid>
		<description><![CDATA[In my last post, I found a use for inverting if statements.&#160; That is, I postulated that it is better to have an explicit else when it’s impossible for that code to be executed.&#160; The argument for just falling through the loop with no else is that why have unnecessary code.   My argument [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://peterkellner.net/2009/10/18/refactor-csharp-if-resharper/">my last post</a>, I found a use for inverting if statements.&#160; That is, I postulated that it is better to have an explicit else when it’s impossible for that code to be executed.&#160; The argument for just falling through the loop with no else is that why have unnecessary code. </p>  <p>My argument is intent.&#160; I personally like to make the intent of my code as clear as possible and having the extra else provides that for me.</p>  <p>Now, for the braces discussion.&#160; That is, is it OK to do this:</p>  <pre class="csharpcode"><span class="kwrd">if</span> (myObject1==<span class="kwrd">null</span>) err = <span class="str">&quot;bad1&quot;</span>;
<span class="kwrd">if</span> (myObject2==<span class="kwrd">null</span>) err = <span class="str">&quot;bad2&quot;</span>;
<span class="kwrd">if</span> (myObject3==<span class="kwrd">null</span>) err = <span class="str">&quot;bad3&quot;</span>;
<span class="kwrd">if</span> (myObject4==<span class="kwrd">null</span>) err = <span class="str">&quot;bad4&quot;</span>;
<span class="kwrd">if</span> (myObject5==<span class="kwrd">null</span>) err = <span class="str">&quot;bad5&quot;</span>;</pre>

<p>
  <br /></p>
<style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>or should you be required by coding standards to do this:</p>
<span id="more-367"></span>

<pre class="csharpcode"><span class="kwrd">if</span> (myObject1==<span class="kwrd">null</span>)
{
 err = <span class="str">&quot;bad1&quot;</span>;
}
<span class="kwrd">if</span> (myObject2==<span class="kwrd">null</span>) 
{
 err = <span class="str">&quot;bad2&quot;</span>;
}
//...</pre>
<style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>I always follow the second, even though the code is clumsier.&#160; I’m a creature of small errors and have found that it can lead to insidious errors when I don’t&#160; That is, I may&#160; say the following and expect both to be executed and will be sadly surprised.</p>

<pre class="csharpcode"><span class="kwrd">if</span> ( myObject==<span class="kwrd">null</span>)  err1 = <span class="str">&quot;bad1&quot;</span>; errorno=3;</pre>

<p>
  <br /></p>
<style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Of course, in the above example, errno will always be 3 whether or not myObject is null or not.</p>

<p>I’m supported in my thinking by <a href="http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=3&amp;tabid=5">Juval Lowy of IDesign</a> in his <a href="http://www.scribd.com/doc/10731655/IDesign-C-Coding-Standard-232">coding standard 2.32</a>. I’m not in 100% agreement with these coding specs (specifically around the use of m_, but overall, I like them very much.</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/ToBraceornottoBraceinCifsandotherConstru_70F0/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/ToBraceornottoBraceinCifsandotherConstru_70F0/image_thumb.png" width="641" height="76" /></a></p>

<p>I’m also supported by one of my favorite .net guys, <a href="http://blogs.msdn.com/brada/articles/361363.aspx">Brad Abrams in his writings</a>.</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/ToBraceornottoBraceinCifsandotherConstru_70F0/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/ToBraceornottoBraceinCifsandotherConstru_70F0/image_thumb_3.png" width="640" height="168" /></a></p>

<p>HTH’s!</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/10/19/codingstandards-csharp-braces/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>LINQ To SQL Very Slow Performance Without Compile (CompileQuery)</title>
		<link>http://peterkellner.net/2009/05/06/linq-to-sql-slow-performance-compilequery-critical/</link>
		<comments>http://peterkellner.net/2009/05/06/linq-to-sql-slow-performance-compilequery-critical/#comments</comments>
		<pubDate>Wed, 06 May 2009 17:23:25 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[LINQ to SQL]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/05/06/linq-to-sql-slow-performance-compilequery-critical/</guid>
		<description><![CDATA[<br/>
In this article, it is shown how important it can be to use the CompileQuery class when using LINQ to SQL.  Doing a simple query in LINQ to SQL verses ADO.NET is shown to run 37 times slower without taking advantage of the Compile feature in LINQ to SQL.  If you are doing the same query over and over in LINQ to SQL, this is a no brainer.  I'm surprised I did not know this myself previously.

<br/><br/>
<img src='http://peterkellner.net/FilesForWebDownload/LINQToSQLVerySlowPerformanceWithoutCompi_88A7/image.png' alt='Performance of LINQ to SQL compiled verses not and ADO.NET' />]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>  <p>At my company, we have been running a workflow process that is taking 6 hours to complete.&#160; This is a new project so we’ve had the good fortune to be able to use the latest Microsoft technologies.&#160; We are a Microsoft shop, so that means <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx">Sql Server 2008</a>, <a href="http://msdn.microsoft.com/en-us/vcsharp/default.aspx">C#,</a> <a href="http://www.asp.net/">ASP.NET</a>, <a href="http://extjs.com/">ExtJS</a>, LINQ to SQL (hoping to move to Entity Framework someday) and others.&#160; After spending all day running performance analysis tools and basically performing a full audit of the 6 hour process, we sadly concluded that our time was being eaten up by <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx">LINQ to SQL</a> processing.&#160; My experience has always been that anything you do on the compiled code side is usually overwhelmed by database access times, usually at least ten to one.&#160; Well, I learned a lot yesterday.</p> <span id="more-302"></span>  <h2>The Problem</h2>  <p>Since I already know the answer, I put together a very trivial problem to solve.&#160; What I want to do is execute one simple SQL statement over and over.&#160;&#160; I’m going to query just one table that actually has no records in it just to make sure the database really has nothing to do.&#160; I’m going to make this connection on my blazingly fast <a href="http://shop.lenovo.com/us/notebooks/thinkpad/w-series">Lenovo W500</a> with a SATA <a href="http://en.wikipedia.org/wiki/Solid-state_drive">SSD</a> running Sql Server 2008&#160; locally.&#160; I’m going to run that simple query first calling just ADO.NET (bare bones using best practices), Then using LINQ to SQL in the way I’ve always used it (and I would say 99% of the other developers out there), then I’m going to compile that LINQ to SQL and run it again.&#160; Actually, I’m going to iterate 2000 times for each of the three conditions.</p>  <p>So, here is the simple SQL I’m executing:</p>  <pre class="csharpcode"><span class="kwrd">SELECT</span> 
  Id,
  FileName,
  FileSize,
  UploadDate,
  DownloadDate,
  ProcessDate
<span class="kwrd">FROM</span>
  LinqTest
<span class="kwrd">WHERE</span> 
  dbo.LinqTest.FileName = <span class="str">'MyVal'</span></pre>

<h2>The Shocking Results</h2>

<p><a href="http://peterkellner.net/FilesForWebDownload/LINQToSQLVerySlowPerformanceWithoutCompi_88A7/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/LINQToSQLVerySlowPerformanceWithoutCompi_88A7/image_thumb.png" width="522" height="317" /></a></p>

<p>Or, for those graphically challenged (like search engines), Here is the actual data.</p>

<table border="0" cellspacing="0" cellpadding="0" width="332"><tbody>
    <tr>
      <td width="177">Test Description</td>

      <td width="153">Seconds Execution for 2000 Iterations</td>
    </tr>

    <tr>
      <td width="177">ADO.NET</td>

      <td width="153">0.48</td>
    </tr>

    <tr>
      <td width="177">Linq2Sql Not Compiled</td>

      <td width="153">18.14</td>
    </tr>

    <tr>
      <td width="177">Linq2Sql Compiled</td>

      <td width="153">0.87</td>
    </tr>
  </tbody></table>

<p>In English, this says that</p>

<ul>
  <li>LINQ to SQL is&#160; <strong>37 times slower</strong> than running a raw ADO.NET Sql query </li>

  <li>LINQ to SQL compiled <strong>1.8 times slower</strong> than running a raw ADO.NET Sql query </li>
</ul>

<p>I’ve read in several places that compiling your LINQ will help, but I have never heard anyone say how <u>drastic</u> the speed improvement can be.&#160; For example, in one of my favorite books (<a href="http://www.amazon.com/exec/obidos/ASIN/1933988169/petkelsblo-20">LINQ in Action</a>) by Fabrice Marguerie and others, he quotes on page 296&#160; a blog post by Rico Mariani titled <a href="http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx">DLINQ (Linq to SQL Performance (Part 1)</a> as saying using a compiled query offers nearly twice the performanced of a non-compiled query, and goes on to say that it brings the performance to within 93% of using a raw data reader.&#160;&#160; Well, suffice it to say I never ran the test myself.&#160; I could have lived with twice, but not 37 times.</p>

<p>Here is the Project File Source: </p>

<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:5092a85c-00d3-4251-820d-af7837a27d56" class="wlWriterSmartContent">
  <p><a href="http://peterkellner.net/FilesForWebDownload/LINQToSQLVerySlowPerformanceWithoutCompi_88A7/LINQ2SQL_CompiledQuery.zip">Project Source (Visual Studio 2008 Solution)</a></p>
</div>

<h2>How to Compile you SQL (seems like a duh kind of thing)</h2>

<p>It’s actually not very hard.&#160; I’m attaching the Visual Studio 2008 project that I ran this test with to this post so you can run it for yourself as well as see an example of how to write the compiled LINQ code.&#160; Below is the method that actually does the work.&#160; I won’t include in this article the actual ADO.NET and LINQ to SQL not compiled code, but you can see those for yourself in the attached solution.</p>

<div class="csharpcode">
  <pre>&#160;</pre>

  <div class="csharpcode">
    <pre class="alt"><span class="lnum">   1:  </span><span class="rem">/// &lt;summary&gt;</span></pre>

    <pre><span class="lnum">   2:  </span><span class="rem">/// This method compiles the LINQ to SQL query and </span></pre>

    <pre class="alt"><span class="lnum">   3:  </span><span class="rem">/// then executes it the number of iterations passed</span></pre>

    <pre><span class="lnum">   4:  </span><span class="rem">/// in.  </span></pre>

    <pre class="alt"><span class="lnum">   5:  </span><span class="rem">/// &lt;/summary&gt;</span></pre>

    <pre><span class="lnum">   6:  </span><span class="rem">/// &lt;param name=&quot;iterations&quot;&gt;Number of iterations&lt;/param&gt;</span></pre>

    <pre class="alt"><span class="lnum">   7:  </span><span class="rem">/// &lt;returns&gt;time in seconds of execution&lt;/returns&gt;</span></pre>

    <pre><span class="lnum">   8:  </span><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">double</span> </pre>

    <pre class="alt"><span class="lnum">   9:  </span>    TestDataAccessSpeedLinq2SqlCompiled(<span class="kwrd">int</span> iterations)</pre>

    <pre><span class="lnum">  10:  </span>{</pre>

    <pre class="alt"><span class="lnum">  11:  </span>    Func&lt;DataClassesDataContext, <span class="kwrd">string</span>, IQueryable&lt;LinqTest&gt;&gt; compiledQuery =</pre>

    <pre><span class="lnum">  12:  </span>        CompiledQuery.Compile((DataClassesDataContext meta,<span class="kwrd">string</span> fileNameForSearch) =&gt;</pre>

    <pre class="alt"><span class="lnum">  13:  </span>                              (from myData <span class="kwrd">in</span> meta.LinqTests</pre>

    <pre><span class="lnum">  14:  </span>                               orderby myData.Id</pre>

    <pre class="alt"><span class="lnum">  15:  </span>                               <span class="kwrd">where</span> myData.FileName.Equals(fileNameForSearch)</pre>

    <pre><span class="lnum">  16:  </span>                               select myData));</pre>

    <pre class="alt"><span class="lnum">  17:  </span>&#160;</pre>

    <pre><span class="lnum">  18:  </span>    var metaNew = <span class="kwrd">new</span> DataClassesDataContext();</pre>

    <pre class="alt"><span class="lnum">  19:  </span>    DateTime startTime = DateTime.Now;</pre>

    <pre><span class="lnum">  20:  </span>    <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; iterations; i++)</pre>

    <pre class="alt"><span class="lnum">  21:  </span>    {</pre>

    <pre><span class="lnum">  22:  </span>        IOrderedQueryable&lt;LinqTest&gt; query = </pre>

    <pre class="alt"><span class="lnum">  23:  </span>            (IOrderedQueryable&lt;LinqTest&gt;) </pre>

    <pre><span class="lnum">  24:  </span>            compiledQuery(metaNew,<span class="kwrd">string</span>.Format(<span class="str">&quot;abcde{0}&quot;</span>, i));</pre>

    <pre class="alt"><span class="lnum">  25:  </span>        List&lt;LinqTest&gt; newList = query.ToList();</pre>

    <pre><span class="lnum">  26:  </span>    }</pre>

    <pre class="alt"><span class="lnum">  27:  </span>    <span class="kwrd">return</span> </pre>

    <pre><span class="lnum">  28:  </span>        DateTime.Now.Subtract(startTime).Duration().TotalSeconds;</pre>

    <pre class="alt"><span class="lnum">  29:  </span>}</pre>
  </div>
  <style type="text/css">



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></div>
<style type="text/css">



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Essentially, line 11 is compiling the code into an instance variable called compileQuery.&#160; Using this instance variable, you can now execute the&#160; LINQ query in a compiled form while still passing in variable data such as fileNameToSearch.&#160; Again, the important thing to note is that one line 24 compiledQuery is already compiled so the IOrderedQueryable result is obtained without having to recompile the LINQ statement.</p>

<h2>Conclusions</h2>

<p>So, from this, it seems that you should always compile your LINQ to SQL queries.&#160; Well, that’s not quite true.&#160; What I’m recommending is that if you have a reason to execute the same query over and over you should strongly consider compiling.&#160; If for example, you are just making a LINQ to SQL call once, there is no benefit because you have to compile it anyway.&#160; Call it ten times?&#160; Well, you will have to decide for yourself.</p>

<p>Forewarned is forearmed!&#160; good luck and hope this helps.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/05/06/linq-to-sql-slow-performance-compilequery-critical/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>A Great New Book on Business Intelligence Solutions and Sql Server 2008 by Lynn Langit</title>
		<link>http://peterkellner.net/2009/02/23/businessintelligencebookreviewlynnlangit/</link>
		<comments>http://peterkellner.net/2009/02/23/businessintelligencebookreviewlynnlangit/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 00:42:49 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=260</guid>
		<description><![CDATA[I’m sure many of you know Lynn Langit.&#160; Her role at Microsoft has been a Developer Evangelist of many of the business software offerings from Microsoft including Sharepoint and SqlServer and it’s many offerings.&#160; She’s always been a wealth of great information about those products and it’s great to see she’s got a book out [...]]]></description>
			<content:encoded><![CDATA[<p>I’m sure many of you know <a href="http://blogs.msdn.com/socaldevgal/about.aspx">Lynn Langit</a>.&#160; Her role at Microsoft has been a Developer Evangelist of many of the business software offerings from Microsoft including <a href="http://www.microsoft.com/Sharepoint/default.mspx">Sharepoint</a> and <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx">SqlServer</a> and it’s many offerings.&#160; She’s always been a wealth of great information about those products and it’s great to see she’s got a book out about one of her favorite topics, Business Intelligence.</p>  <p>So far, I’ve read the first four chapters and have skimmed the rest.&#160; I am so far very impressed with both how well it’s written and the depth of topics the book covers.&#160; As I read more, I’ll come back and update this post.&#160; I have no doubts I will get a lot out of this book, as I’m sure practically anyone else who buys it will also.</p> <span id="more-260"></span>  <p>If you want to read more of Lynn’s stuff, check out her blog at <a title="http://blogs.msdn.com/socaldevgal/" href="http://blogs.msdn.com/socaldevgal/">http://blogs.msdn.com/socaldevgal/</a></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:762c08a5-66d8-456c-b756-04bdd0f0bf6b" class="wlWriterSmartContent">   <table border="0" cellspacing="0" cellpadding="2" width="400"><tbody>       <tr>         <td valign="top" width="400">           <p><a title="Smart Business Intelligence Solutions with Microsoft® SQL Server® 2008 (PRO-Developer): Lynn Langit, Kevin S. Goff, Davide Mauri, Sahil Malik, John Welch: Books" href="http://www.amazon.com/exec/obidos/ASIN/0735625808/petkelsblo-20"><img style="float: left" border="0" align="left" src="http://images.amazon.com/images/P/0735625808.01.MZZZZZZZ.jpg" />Smart Business Intelligence Solutions with Microsoft® SQL Server® 2008 (PRO-Developer): Lynn Langit, Kevin S. Goff, Davide Mauri, Sahil Malik, John Welch: Books</a></p>         </td>       </tr>     </tbody></table> </div>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/02/23/businessintelligencebookreviewlynnlangit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Experience with Visual Studio 2008 Database Edition, I love it!!!</title>
		<link>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/</link>
		<comments>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 22:06:11 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/</guid>
		<description><![CDATA[As a developer who has spent much of my life doing DBA type work, I really appreciate the simplicity and elegance of what Microsoft Visual Studio Team has put together with the Database Edition and can be seen for sale here as the 

Microsoft Visual Studio 2010 Premium with MSDN Download &#8211; Download Direct from [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer who has spent much of my life doing DBA type work, I really appreciate the simplicity and elegance of what <a href="http://msdn.microsoft.com/en-us/vsts2008/products/bb933747.aspx">Microsoft Visual Studio Team</a> has put together with the <a href="http://blogs.msdn.com/gertd/archive/2007/11/21/visual-studio-team-system-2008-database-edition.aspx">Database Edition</a> and can be seen for sale here as the 

<a href="http://click.linksynergy.com/fs-bin/click?id=cLhVEJVzoSE&#038;offerid=166833.737&#038;type=2&#038;subid=0">Microsoft Visual Studio 2010 Premium with MSDN Download &#8211; Download Direct from Microsoft</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=cLhVEJVzoSE&#038;bids=166833.737&#038;type=2&#038;subid=0" >

 I&#8217;ll first try and explain in a nutshell what it is.&#160; Then I&#8217;ll go through an example of creating a Visual Studio Database Project out of a site I&#8217;ve been working on to show the steps.&#160; Finally, I&#8217;ll give a short summary reliving the experience and giving you some other pointers that may help you get through the experience.</p>

<h3>What is VS2008 Database Edition?</h3>

<p>Basically, what VS2008 does is to first process your existing schema into hundreds (maybe thousands) of little files.&#160; That is, each file is one database thing. That thing might be a table definition, a stored procedure, a trigger, a constraint, a foreign key, etc.&#160; The beauty of this is that now, each thing can be tracked separately.&#160; Say for example, you want to update just one table and someone else on your team wants to update another table in the same schema.&#160; Since the files are now separate files, it&#8217;s no problem.&#160; When you grab the latest changes from source control, you will get your friends changes and he will get yours.&#160; Very very clean!</p>
<div id='extendedEntryBreak' name='extendedEntryBreak'></div>

<p>Also, it has a very powerful comparison engine.&#160; Say you update your data outside of this project.&#160; VS2008 Database Edition will compare your definitions in all these little files with either a sql script you generate, or it will connect to an external database and compare to that.&#160; Me personally, I like to use a tool called <a href="http://www.sqlmanager.net/en/products/studio/mssql">SqlManager</a> to manage my data.&#160; I can continue to do that, then when I&#8217;ve made my changes, I can simply connect VS2008 Database Edition to my updated development database and it will automatically figure out the changes.</p>

<p>So, you may ask, what version do I need to run this of Visual Studio?&#160; The answer is in this link:&#160; <a title="http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx" href="http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx">http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx</a></p>

<h3>Here We Go, Let&#8217;s do an Example</h3>

<p>So, first, I will open my existing solution which has a web project in it, a data access project as well as other projects.&#160; Then, I create the new Database solution by saying File/Open/New Project/Database Project.</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb.png" width="395" height="208" /></a></p>

<p>Then, we follow the wizard&#8230;</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_3.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_3.png" width="244" height="182" /></a></p>

<p>Taking defaults&#8230;</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_4.png" width="244" height="182" /></a></p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_5.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_5.png" width="244" height="182" /></a></p>

<p>Now, I choose my schema.</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_6.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_6.png" width="244" height="182" /></a></p>

<p>Press Start&#8230;</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_7.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_7.png" width="244" height="182" /></a></p>

<p>Once you&#8217;ve done that, you&#8217;ll now have your schema spread out across your project in little files.&#160; Below is what the &quot;file based&quot; view of your schema looks like.</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_8.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_8.png" width="412" height="295" /></a></p>

<p>Notice that the file we are looking at also includes comments for both the table and the columns using the standard extended property documentation format as follows:</p>

<pre class="csharpcode"><span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> sp_addextendedproperty @name = N<span class="str">'MS_Description'</span>, 
@<span class="kwrd">value</span> = N<span class="str">'tracks all changes from each camp

title;link;guid;pubDate;category;description'</span>, @level0type = N<span class="str">'SCHEMA'</span>, 
@level0name = N<span class="str">'dbo'</span>, @level1type = N<span class="str">'TABLE'</span>, 
@level1name = N<span class="str">'CampFeed'</span>;


<span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> sp_addextendedproperty @name = N<span class="str">'MS_Description'</span>, 
@<span class="kwrd">value</span> = N<span class="str">'if true, this is the main news feed from the site.  
there should only be one main news feed from any site.  this would 
not be feeds like twitter'</span>, @level0type = N<span class="str">'SCHEMA'</span>, 
@level0name = N<span class="str">'dbo'</span>, 
@level1type = N<span class="str">'TABLE'</span>, @level1name = N<span class="str">'CampFeed'</span>, 
@level2type = N<span class="str">'COLUMN'</span>, @level2name = N<span class="str">'PrimaryFeed'</span>;</pre>

<pre class="csharpcode">&#160;</pre>

<pre class="csharpcode">Now, when you actually build the project as follows:</pre>

<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_9.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_9.png" width="242" height="244" /></a> </pre>

<p>it will generate the full script combining all the files back into one again. Here is where it puts it:</p>

<pre class="csharpcode">&#160;</pre>

<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/FirstExperiencewithVisualStudio2008Datab_A011/image_thumb_10.png" width="414" height="332" /></a> </pre>

<pre class="csharpcode">&#160;</pre>

<p>So, that&#8217;s about it for now. I haven&#8217;t gone into any of the ways to compare and update your schema based on external changes, but we can leave that for another post.</p>

<p>To see a great video by <a href="http://blog.hundhausen.com/">Richard Hundhausen</a>, President of <a title="http://www.accentient.com/" href="http://www.accentient.com/">Accentient</a>, a <a href="http://msdn.microsoft.com/en-us/vsts2008/aa718934.aspx">Team Systems</a> Consulting company, go to this link:&#160; <a title="http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx" href="http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx">http://msdn.microsoft.com/en-us/vsts2008/cc659682.aspx</a></p>

<p>Also, if you are using Sql Server 2008, make sure you install visual studio 2008 sp1, then go to this link and install the download:&#160; <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&amp;displaylang=en</a></p>

<h3>Conclusions</h3>

<p>From what I can tell, this Visual Studio Database Edition will be a huge help in building database schema&#8217;s and database programs (sp&#8217;s, triggers,etc.) in a collaborative environment.&#160;&#160; If you have the license to use this, I strongly recommend it.&#160; It is definitely going to be part of my tool kit for now on.&#160; Even if I&#8217;m the only author in the project.</p>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/01/17/visual-studio-database-edition-review-sqlserver2008/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>View a Generic List with ASP.NET MVC. Step by Step With Preview 5</title>
		<link>http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/</link>
		<comments>http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 18:35:28 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/</guid>
		<description><![CDATA[I&#8217;ve just started (within the past 2 days) learning and building a prototype with Microsoft&#8217;s new MVC platform.&#160; It&#8217;s really just another project type in Visual Studio 2008, but it changes the way you write asp.net applications.&#160; So far I like it, but I&#8217;m still on the honeymoon.&#160; I have not really tried to do [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started (within the past 2 days) learning and building a prototype with <a href="http://forums.asp.net/">Microsoft&#8217;s new MVC platform</a>.&#160; It&#8217;s really just another project type in <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2008</a>, but it changes the way you write asp.net applications.&#160; So far I like it, but I&#8217;m still on the honeymoon.&#160; I have not really tried to do anything complex yet, and because it&#8217;s new to me, the simple things are still hard.&#160; <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx">Scott Guthrie&#8217;s</a> posts posts have been helpful, as well as reading a pre-release of Manning&#8217;s upcoming book <a href="http://manning.com/palermo/">ASP.NET MVC In Action</a> by <a href="http://jeffreypalermo.com/">Jeffrey Palermo</a>, <a href="http://www.flux88.com/">Ben Scheirman</a> and <a href="http://grabbagoft.blogspot.com/">Jimmy Bogard</a>.</p> <span id="more-158"></span>  <p>So, as is normal, when I learn something new, the most obvious things just don&#8217;t seem to work.&#160; In this case, I&#8217;m just trying to make a web page that shows a list of data on a page.&#160; I&#8217;m not going to try and teach MVC here, but if you are like me and struggled with this, this should help you get through some of the tough spots. My plan is to start a new MVC project with Visual Studio and show you what is necessary to generate the list.&#160; Instead of going after a database, I&#8217;m going to use an simple business object class so you can run this without connecting to a database.&#160; Not sure about you, but I never seem to be able to get the databases from example code working.&#160; Scott Guthrie uses the Northwind databases Product table, and after spending about 15 minutes searching, all I could find was a <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;displaylang=en">Northwind database from sqlserver 2000</a> that does not have a Product table.&#160; With my demo, you won&#8217;t have to worry about that.&#160; By the way, here is the project if you want to download it in action.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:18d43e01-4549-4fde-8ca6-c7b4b7385fac:176475a3-eab9-41db-8107-c37ea0c2a70b" class="wlWriterSmartContent">   <p>Download Solution &#8211; <a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/Solution.zip">Solution.zip</a></p> </div>  <p>So, Here we go.&#160; First thing, Open Visual Studio 2008 and create a new MVC Project (not a web site, this will give you a csproj type file)</p>  <p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb.png" width="535" height="424" /></a></p>  <p>Answer the next question YES because of course you want a Test Project.</p>  <p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_3.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_3.png" width="424" height="284" /></a></p>  <p>You should get a Solution that looks like this:</p>  <p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_4.png" width="197" height="330" /></a></p>  <p>Now, Add the business object that I will be using for this rest of this demonstration.&#160; It&#8217;s in the project file, our you just download it here (put this in your Models Directory).</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:73729366-c7a7-43f3-a538-5ec829978430" class="wlWriterSmartContent">   <p>BusinessObjectClass.cs <a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/BusinessObjectClass.cs" target="_blank">BusinessObjectClass.cs</a></p> </div>  <p>Now, let&#8217;s create the MVC Controller.&#160; Highlight the Controller&#8217;s Folder and say Add Item (TMI if I show you that).&#160; Here is the dialog.&#160; Create the name of your controller with the syntax {Name}Controller.&#160; In my case, the name is EmailListControler.cs.</p>  <p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_5.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_5.png" width="424" height="293" /></a></p>  <p>Add the following code to your EmailListController.cs file to retrieve some data and return it as a View (which will be processed by the View Page coming up).</p>  <div class="csharpcode">   <pre class="alt"><span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre><span class="kwrd">using</span> System.Linq;</pre>

  <pre class="alt"><span class="kwrd">using</span> System.Web.Mvc;</pre>

  <pre>&#160;</pre>

  <pre class="alt"><span class="kwrd">namespace</span> Solution.Controllers</pre>

  <pre>{</pre>

  <pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> EmailListController : Controller</pre>

  <pre>    {</pre>

  <pre class="alt">        <span class="kwrd">public</span> ActionResult Index()</pre>

  <pre>        {</pre>

  <pre class="alt">            var businessObject = <span class="kwrd">new</span> BusinessObject();</pre>

  <pre>            List&lt;BusinessObjectItem&gt; members = </pre>

  <pre class="alt">                businessObject.GetMembers();</pre>

  <pre>            <span class="kwrd">return</span> View(<span class="str">&quot;Index&quot;</span>, members);</pre>

  <pre class="alt">        }</pre>

  <pre>    }</pre>

  <pre class="alt">}<span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre><span class="kwrd">using</span> System.Linq;</pre>

  <pre class="alt"><span class="kwrd">using</span> System.Web.Mvc;</pre>

  <pre>&#160;</pre>

  <pre class="alt"><span class="kwrd">namespace</span> Solution.Controllers</pre>

  <pre>{</pre>

  <pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> EmailListController : Controller</pre>

  <pre>    {</pre>

  <pre class="alt">        <span class="kwrd">public</span> ActionResult Index()</pre>

  <pre>        {</pre>

  <pre class="alt">            var businessObject = <span class="kwrd">new</span> BusinessObject();</pre>

  <pre>            List&lt;BusinessObjectItem&gt; members = </pre>

  <pre class="alt">                businessObject.GetMembers();</pre>

  <pre>            <span class="kwrd">return</span> View(<span class="str">&quot;Index&quot;</span>, members);</pre>

  <pre class="alt">        }</pre>

  <pre>    }</pre>

  <pre class="alt">}</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Then, create a new folder called EmailList under the Views folder.</p>

<p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_6.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_6.png" width="244" height="142" /></a></p>

<p>Then, create a MVCViewPage in the EmailList folder called Index.aspx.</p>

<p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_7.png"><img alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_7.png" width="612" height="360" /></a></p>

<p>(Actually, choose MVC View Content Page, not MVC View Page)</p>

<p>Then, chose the Master Page to use as follows (there is only one):</p>

<p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_8.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_8.png" width="579" height="354" /></a></p>

<p>The View will be referring to the ViewData.Model which somehow is associated with how the code behind is implemented. Make sure you have the ViewPage look like the following and the data type specified as below.&#160; This is the file Index.aspx.cs which is in your email directory.</p>

<div class="csharpcode">
  <pre class="alt"><span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre><span class="kwrd">using</span> System.Web.Mvc;</pre>

  <pre class="alt">&#160;</pre>

  <pre><span class="kwrd">namespace</span> Solution.Views.EmailList</pre>

  <pre class="alt">{</pre>

  <pre>    <span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Index :</pre>

  <pre class="alt">        ViewPage&lt;IEnumerable&lt;BusinessObjectItem&gt;&gt;</pre>

  <pre>    {</pre>

  <pre class="alt">    }</pre>

  <pre>}</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Now, for the Index.aspx file which is also in your Views/EmailList directory, enter the following between the content tags.</p>

<p>&#160;</p>

<div class="csharpcode">
  <pre class="alt">&lt;table border=<span class="str">&quot;1&quot;</span>&gt;</pre>

  <pre>    &lt;tr&gt;</pre>

  <pre class="alt">        &lt;td&gt;</pre>

  <pre>            &lt;strong&gt;Name&lt;/strong&gt;</pre>

  <pre class="alt">        &lt;/td&gt;</pre>

  <pre>        &lt;td&gt;</pre>

  <pre class="alt">            &lt;strong&gt;&lt;strong&gt;Email Address&lt;/strong&gt;</pre>

  <pre>        &lt;/td&gt;</pre>

  <pre class="alt">    &lt;/tr&gt;</pre>

  <pre>    &lt;% <span class="kwrd">foreach</span> (var emailItem <span class="kwrd">in</span> ViewData.Model)</pre>

  <pre class="alt">       { %&gt;</pre>

  <pre>    &lt;tr&gt;</pre>

  <pre class="alt">        &lt;td&gt;</pre>

  <pre>            &lt;%= emailItem.Name %&gt;</pre>

  <pre class="alt">        &lt;/td&gt;</pre>

  <pre>        &lt;td&gt;</pre>

  <pre class="alt">            &lt;%=emailItem.Email %&gt;</pre>

  <pre>        &lt;/td&gt;</pre>

  <pre class="alt">    &lt;/tr&gt;</pre>

  <pre>    &lt;% } %&gt;</pre>

  <pre class="alt">&lt;/table&gt;</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Notice that you have intellisense working on your foreach items.</p>

<p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_9.png"><img alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_9.png" width="554" height="141" /></a></p>

<p>Finally, go to your Master Page and add a link for this new EmailList as follows.&#160; That is, change the file /Views/Shared/Site.Master</p>

<div class="csharpcode">
  <pre class="alt">&lt;ul id=<span class="str">&quot;menu&quot;</span>&gt;              </pre>

  <pre>    &lt;li&gt;&lt;%= Html.ActionLink(<span class="str">&quot;Home&quot;</span>, <span class="str">&quot;Index&quot;</span>, <span class="str">&quot;Home&quot;</span>)%&gt;&lt;/li&gt;</pre>

  <pre class="alt">    &lt;li&gt;&lt;%= Html.ActionLink(<span class="str">&quot;About Us&quot;</span>, <span class="str">&quot;About&quot;</span>, <span class="str">&quot;Home&quot;</span>)%&gt;&lt;/li&gt;</pre>

  <pre>    &lt;li&gt;&lt;a href=<span class="str">&quot;/EmailList&quot;</span>&gt;Email List&lt;/a&gt;&lt;/li&gt;</pre>

  <pre class="alt">&lt;/ul&gt;</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>As you can see, I don&#8217;t quite grock the ActionLinke parameters so I just put in a standard anchor tag.&#160; Please comment below on what it should be to be able to reference /EmailList and I will update the article.&#160; For now, lunch is coming and I need to run.</p>

<p>When you finally run that app, you get this for your new output.&#160; Notice the New Email List Tab.</p>

<p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_10.png" width="625" height="382" /></a></p>

<p>That&#8217;s it for now.&#160; Hope this helps!</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to User HttpHandler such as .ashx file with IIS7 Integrated Mode, Webfarm Environment</title>
		<link>http://peterkellner.net/2008/09/06/iis7-httphandlers-handlers-integrated-mode-webfarm/</link>
		<comments>http://peterkellner.net/2008/09/06/iis7-httphandlers-handlers-integrated-mode-webfarm/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 15:20:06 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[IIS7]]></category>
		<category><![CDATA[WebFarm]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/09/06/iis7-httphandlers-handlers-integrated-mode-webfarm/</guid>
		<description><![CDATA[Recently, we&#8217;ve moved our hosting for the Silicon Valley Code Camp to MOSSO, which is a hosted web farm.&#160; In order to run modules and handlers, it seems it&#8217;s necessary to run in IIS7&#8217;s integrated mode.&#160; Once this is set, other small issues creep up like for example you can no longer run HttpHandler&#8217;s from [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, we&#8217;ve moved our hosting for the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> to <a href="http://mosso.com">MOSSO</a>, which is a hosted web farm.&#160; In order to run modules and handlers, it seems it&#8217;s necessary to run in <a href="http://www.iis.net/">IIS7&#8217;s</a> <a href="http://weblogs.asp.net/mschwarz/archive/2008/04/14/ajax-net-and-iis-7-integrated-mode.aspx">integrated mode</a>.&#160; Once this is set, other small issues creep up like for example you can no longer run <a href="http://msdn.microsoft.com/en-us/library/ms998532.aspx">HttpHandler&#8217;s</a> from the standard HttpHandler&#8217;s section in your <a href="http://msdn.microsoft.com/en-us/library/aa719558.aspx">web.config</a> file (see below)</p>  <div class="csharpcode">   <pre class="alt">&lt;httpHandlers&gt;</pre>

  <pre>            &lt;remove verb=<span class="str">&quot;*&quot;</span> path=<span class="str">&quot;*.asmx&quot;</span>/&gt;</pre>

  <pre class="alt">            &lt;add verb=<span class="str">&quot;*&quot;</span> path=<span class="str">&quot;*.asmx&quot;</span> validate=<span class="str">&quot;false&quot; ...</span></pre>

  <pre>            &lt;add verb=<span class="str">&quot;*&quot;</span> path=<span class="str">&quot;*_AppService.axd&quot;</span> validate=<span class="str">&quot;false&quot;</span> ...</pre>

  <pre class="alt">            &lt;add verb=<span class="str">&quot;GET,HEAD&quot;</span> path=<span class="str">&quot;ScriptResource.axd&quot;</span> type=<span class="str">&quot;System.Web.Handlers.ScriptResourceHandler,..</span></pre>

  <pre>            &lt;add type=<span class="str">&quot;PeterKellner.Utils.CaptchaTypeHandler&quot;</span> verb=<span class="str">&quot;GET&quot;</span> path=<span class="str">&quot;CaptchaType.ashx&quot;</span>/&gt;</pre>

  <pre class="alt">&lt;/httpHandlers&gt;</pre>
</div>

<p>&#160;</p>
<span id="more-147"></span>

<p>In order to make this work, you have to do two things.&#160; First, as MOSSO suggest on their web site <a title="http://help.mosso.com/article.php?id=260" href="http://help.mosso.com/article.php?id=260">http://help.mosso.com/article.php?id=260</a> you need to set a section in your <a href="http://msdn.microsoft.com/en-us/magazine/cc163453.aspx">&lt;system.webServer&gt;</a> section called &lt;staticContent&gt;.&#160; Second, you need to add to the the same handler you defined in the old section to the &lt;handlers&gt; section of the &lt;system.webServer&gt; section.&#160; Make sure you add a name tag because that&#8217;s required in this section, where as it&#8217;s not required in the &lt;HttpHandlers&gt; section.</p>

<div class="csharpcode">
  <pre class="alt">    <span class="kwrd">&lt;</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;</span><span class="html">validation</span> <span class="attr">validateIntegratedModeConfiguration</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre class="alt">    <span class="kwrd">&lt;</span><span class="html">staticContent</span><span class="kwrd">&gt;</span></pre>

  <pre>      <span class="kwrd">&lt;</span><span class="html">mimeMap</span> <span class="attr">fileExtension</span><span class="kwrd">=&quot;.ashx&quot;</span> <span class="attr">mimeType</span><span class="kwrd">=&quot;text/html&quot;</span> <span class="kwrd">/&gt;</span></pre>

  <pre class="alt">    <span class="kwrd">&lt;/</span><span class="html">staticContent</span><span class="kwrd">&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;</span><span class="html">modules</span>  <span class="attr">runAllManagedModulesForAllRequests</span><span class="kwrd">=&quot;true&quot;</span>  <span class="kwrd">&gt;</span></pre>

  <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptModule&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre>            <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptModule&quot;</span> <span class="attr">preCondition</span><span class="kwrd">=&quot;managedHandler&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Handlers....</span></pre>

  <pre class="alt">      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">type</span><span class="kwrd">=&quot;HealthMonitor.GeneralErrorModule,HealthMonitor&quot;</span> <span class="attr">name</span><span class="kwrd">=&quot;GeneralErrorModule&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;/</span><span class="html">modules</span><span class="kwrd">&gt;</span></pre>

  <pre class="alt">        <span class="kwrd">&lt;</span><span class="html">handlers</span><span class="kwrd">&gt;</span></pre>

  <pre>            <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;WebServiceHandlerFactory-Integrated&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptHandlerFactory&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre>            <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptHandlerFactoryAppServices&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptResource&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre>            <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptHandlerFactory&quot;</span> <span class="attr">verb</span><span class="kwrd">=&quot;*&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;*.asmx&quot;</span> <span class="attr">preCondition</span><span class="kwrd">=&quot;integratedMode&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;System....</span></pre>

  <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptHandlerFactoryAppServices&quot;</span> <span class="attr">verb</span><span class="kwrd">=&quot;*&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;*_AppService.axd&quot;</span> <span class="attr">preCondition</span><span class="kwrd">=&quot;integratedMode&quot;</span>...</pre>

  <pre>            <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;ScriptResource&quot;</span> <span class="attr">preCondition</span><span class="kwrd">=&quot;integratedMode&quot;</span> <span class="attr">verb</span><span class="kwrd">=&quot;GET,HEAD&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;ScriptResource.axd&quot;</span> <span class="attr">...</span></pre>

  <pre class="alt">      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;CapthaTypeHandler&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;PeterKellner.Utils.CaptchaTypeHandler&quot;</span> <span class="attr">verb</span><span class="kwrd">=&quot;GET&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;CaptchaType.ashx&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;/</span><span class="html">handlers</span><span class="kwrd">&gt;</span></pre>

  <pre class="alt">    <span class="kwrd">&lt;/</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;</span><span class="html">runtime</span><span class="kwrd">&gt;</span></pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Hope this saves you some time!</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/09/06/iis7-httphandlers-handlers-integrated-mode-webfarm/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to do URL Rewrites with ASP.NET 2.0 3.0 3.5 on IIS6 and IIS7 and What is Wild Card Mapping</title>
		<link>http://peterkellner.net/2008/08/24/urlrewrite-with-aspnet-urlrewriter-wildcard-mapping-iis6-iis7/</link>
		<comments>http://peterkellner.net/2008/08/24/urlrewrite-with-aspnet-urlrewriter-wildcard-mapping-iis6-iis7/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 03:19:02 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[How Things Work]]></category>
		<category><![CDATA[Page Handlers]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/08/24/urlrewrite-with-aspnet-urlrewriter-wildcard-mapping-iis6-iis7/</guid>
		<description><![CDATA[<p>A Step by step tutorial on how to use WildCard Mapping for processing URL requests.  It includes how to set it with IIS6 and IIS7.  It also discusses the theory behind how it works and talks about a great open source packaged called URLRewriter.Net.  Basically, how to resolve http://mydomain.com/Home to http://mydomain.com/HomeSite/Home.aspx which looks so much nicer.</p>]]></description>
			<content:encoded><![CDATA[<h2>The Problem</h2>  <p>Over the past several years I&#8217;ve found myself running into the same problem over and over so I thought I&#8217;d blog the solution so at least I don&#8217;t waste time figuring it out again.&#160; So, when do you need this?&#160; The answer for me is that I want to be able reference a web site without having to expose the underlying site structure.&#160; For example, on the home page of my business, I want people to be able to type <a href="http://73rdstreet.com/Home">http://73rdstreet.com/Home</a> and be taken to <a title="http://www.73rdstreet.com/HomeSite/Home.aspx" href="http://www.73rdstreet.com/HomeSite/Home.aspx">http://www.73rdstreet.com/HomeSite/Home.aspx</a>. </p>  <h2>The Symptom</h2>  <p>You may see errors that say something like: </p>  <p>Server Error in Application &#8230; HTTP Error 404.0 &#8211; Not Found</p> <span id="more-142"></span>  <p><strong>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</strong></p>  <p><a href="http://msdn.microsoft.com/en-us/library/system.web.httpapplication.maprequesthandler.aspx">MapRequestHandler</a> StaticFile</p>  <p>And the screen may show something like this.</p>  <p><a href="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/x.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="x" src="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/x_thumb.png" width="537" height="397" /></a></p>  <p>If this happens, read on. </p>  <h2>Theory</h2>  <p>The first thing to understand is that <a href="http://www.microsoft.com/WindowsServer2003/IIS/Default.mspx">IIS</a> by default will pass to the asp.net process only the requests that have a certain file extension.&#160; That is, <a href="http://www.eggheadcafe.com/articles/20030113.asp">aspx,ashx</a>,etc.&#160; Basically, only file extensions that have a handler defined for them to be processed by.&#160; Other URL&#8217;s that don&#8217;t meet the criteria are not passed to IIS.&#160; This includes no file extension at all.&#160; There is a good reason for this.&#160; One, it makes processing of things like images (jpg&#8217;s, gif&#8217;s, etc.) faster because they do not every have to be processed through the asp.net worker process.&#160; Secondly, it lowers the exposure of the asp.net worker process so that it is less likely to be compromised. </p>  <p>So, the first thing that has to be done is to tell IIS to pass all requests through using something called Wild Card Mapping.&#160; Then, once this is done, the request comes through to the asp.net worker process regardless of what it is.&#160; As we know, the place that we would have to process this is an <a href="http://msdn.microsoft.com/en-us/library/9b9dh535.aspx">HttpModule</a>.&#160; The reason is that since it&#8217;s not a page yet, we have no idea what to do with it.&#160; Basically modules let you tap into the request at different stages.&#160; To do the rewrite from ../Home to ../HomeSite/Home.aspx we want to tap into the <a href="http://msdn.microsoft.com/en-us/library/ms227673.aspx">Application_BeginRequest</a> event.&#160; The Context.<a href="http://msdn.microsoft.com/en-us/library/ms223300.aspx">RewritePath</a> method is called at that point to force a new path based on what we want (hopefully not hard coded).</p>  <p>After the ReWritePath is set, the page is processed as if is going to the correct page.</p>  <h2>How To Set Wild Card Mapping in IIS6</h2>  <p>To Set Wild Care Mapping in IIS6 you need to do the following.</p>  <p>Run inetmgr and navigate to the Properties page of the website you want to set.</p>  <p><a href="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/test.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="test" src="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/test_thumb.jpg" width="272" height="332" /></a>&#160;</p>  <p>Then, from the properties page, click the Configuration button as shown below.</p>  <p><a href="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/t.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="t" src="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/t_thumb.jpg" width="280" height="281" /></a></p>  <p>Then, press the insert button on the configuration screen and see the following screen and then click on the insert button.</p>  <p><a href="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/t6.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="t[6]" src="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/t6_thumb.jpg" width="288" height="320" /></a></p>  <p>Now, insert your asp.net isapi dll.&#160; On my system, the file is here:&#160; C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.&#160; Make sure to uncheck the box &quot;Verify that file exists&quot;.</p>  <p><a href="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/t9.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="t[9]" src="http://www.peterkellner.net/FilesForWebDownload/How.0plusonIIS6andIIS7andWhatisWildCardM_10C46/t9_thumb.jpg" width="430" height="126" /></a></p>  <p>That&#8217;s it! Now, all requests will be processed through you asp.net pipeline so you will be able to intercept anything on the URL you want.&#160; Be careful though, you may get more than you ask for! </p>  <h2>How To Set Wildcard Mapping in IIS7</h2>  <p>In IIS7 things are a little different.&#160; First thing you need to do is unlock the config section &quot;handlers&quot;. You do this by bring up a DOS prompt and entering the command: </p>  <p>C:\Windows\System32\inetsrv&gt;appcmd.exe unlock config /section:system.webserver/handlers</p>  <p>Then, you can set your wildcard handler in your web.config file as follows.</p>  <p>Now, the default handlers will be executed in your web.config file, and of course, all the defaults for that are in the chain of files that inherits from.&#160; For more details on that, see this FAQ: <a href="http://forums.asp.net/p/1117776/1736929.aspx">Configuration Files FAQs (web.config, machine.config&#8230;)</a>.</p>  <p>You may need to add the wildcard mapper handler to your web.config.&#160; To do this, you would put the following in your web.config</p>  <pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span> <span class="attr">encoding</span><span class="kwrd">=&quot;UTF-8&quot;</span>?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">handlers</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;WildCard&quot;</span> <span class="attr">path</span><span class="kwrd">=&quot;*&quot;</span> <span class="attr">verb</span><span class="kwrd">=&quot;*&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;sampletype&quot;</span> <span class="attr">resourceType</span><span class="kwrd">=&quot;Unspecified&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">handlers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>

<p>Now, you should be set. See the next section for a good method for actually doing the remapping, which is why we went down this path in the first place.</p>

<h2>Implementing a URL ReWriter for Mapping ../Home to ../HomeSite/Home.aspx</h2>

<p>So, as discussed in the theory section above, you could write your own code to map what you want to where you want it.&#160; You could put in your global.asax some code for the Application_BeginRequest and make a big case statement for everything you want to do.&#160; Well, as we know, that would give your code a bad smell and we don&#8217;t want that because soon, you will find yourself using cut and paste and other problematic crutches.</p>

<p>So, to avoid all that, and do what <a href="http://weblogs.asp.net/scottgu">Scott Guthrie</a> suggests, use the open source package <a href="http://urlrewriter.net/">UrlRewriter.NET</a>.&#160; It&#8217;s light-weight and configurable through a small section in your web.config. Before putting in the what to do, here are the steps to make UrlRewriter work in a very simple way (the way I use it on my <a href="http://73rdstreet.com/Home">company home page</a>.</p>

<p>In your &lt;System.web&gt; of your web.config place a definition for a new config section where you will put your rewrites</p>

<div class="csharpcode">
  <pre class="alt"><span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;</span><span class="html">configSections</span><span class="kwrd">&gt;</span></pre>

  <pre class="alt">      <span class="kwrd">&lt;</span><span class="html">section</span> <span class="attr">name</span><span class="kwrd">=&quot;rewriter&quot;</span> <span class="attr">requirePermission</span><span class="kwrd">=&quot;false&quot;</span> </pre>

  <pre>        <span class="attr">type</span><span class="kwrd">=&quot;Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter&quot;</span><span class="kwrd">/&gt;</span></pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>&#160;</p>

<p>Then, put the module that actually does the work of the rewrite as described in the theory section above</p>

<div class="csharpcode">
  <pre class="alt">&lt;system.web&gt;</pre>

  <pre>   &lt;httpModules&gt;</pre>

  <pre class="alt">     &lt;add name=<span class="str">&quot;UrlRewriter&quot;</span> </pre>

  <pre>           type=<span class="str">&quot;Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter&quot;</span> /&gt;</pre>

  <pre class="alt">     &lt;/httpModules&gt;</pre>

  <pre>       ..</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Then, further down in your web.config put</p>

<div class="csharpcode">
  <pre class="alt"><span class="kwrd">&lt;</span><span class="html">system.webServer</span><span class="kwrd">&gt;</span></pre>

  <pre>  <span class="kwrd">&lt;</span><span class="html">validation</span> <span class="attr">validateIntegratedModeConfiguration</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre class="alt">  <span class="kwrd">&lt;</span><span class="html">modules</span><span class="kwrd">&gt;</span></pre>

  <pre>    <span class="kwrd">&lt;</span>add name=&quot;UrlRewriter&quot;</pre>

  <pre class="alt">         type=&quot;Intelligencia.U</pre>
</div>

<div class="csharpcode">&#160;</div>

<div class="csharpcode">And, Finally to actually do the redirect you need to put a new &lt;rewriter&gt; tag with a list of redirects in it.</div>

<div class="csharpcode">&#160;</div>

<div class="csharpcode">
  <pre class="alt"><span class="kwrd">&lt;</span><span class="html">rewriter</span><span class="kwrd">&gt;</span></pre>

  <pre>  <span class="kwrd">&lt;</span><span class="html">rewrite</span> <span class="attr">url</span><span class="kwrd">=&quot;~/Home&quot;</span> <span class="attr">to</span><span class="kwrd">=&quot;~/pages/Home.aspx&quot;</span><span class="kwrd">/&gt;</span></pre>

  <pre class="alt"><span class="kwrd">&lt;/</span><span class="html">rewriter</span><span class="kwrd">&gt;</span></pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>That&#8217;s it!&#160; You are done.&#160; Hope this helps, or at least helps me the next time I&#8217;m searching for the same problem (for the 4th time at least).</p>

<p>References:</p>

<ul>
  <li><a title="http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx" href="http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx">http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx</a> </li>

  <li><a title="http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx" href="http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx">http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx</a> </li>

  <li><a title="http://urlrewriter.net/" href="http://urlrewriter.net/">http://urlrewriter.net/</a> </li>

  <li><a title="http://forums.asp.net/t/1240344.aspx" href="http://forums.asp.net/t/1240344.aspx">http://forums.asp.net/t/1240344.aspx</a> </li>

  <li><a title="http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx" href="http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx">http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx</a> </li>

  <li><a title="http://professionalaspnet.com/archive/2007/07/27/Create-an-HttpModule-to-Process-Wildcard-Extension-Mapping-in-ASP.NET.aspx" href="http://professionalaspnet.com/archive/2007/07/27/Create-an-HttpModule-to-Process-Wildcard-Extension-Mapping-in-ASP.NET.aspx">http://professionalaspnet.com/archive/2007/07/27/Create-an-HttpModule-to-Process-Wildcard-Extension-Mapping-in-ASP.NET.aspx</a> </li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/08/24/urlrewrite-with-aspnet-urlrewriter-wildcard-mapping-iis6-iis7/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Refactoring With ReSharper, Some Very Nice C# fixes I often use</title>
		<link>http://peterkellner.net/2008/07/03/code-refactoring-with-resharper/</link>
		<comments>http://peterkellner.net/2008/07/03/code-refactoring-with-resharper/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 13:59:34 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/07/03/code-refactoring-with-resharper/</guid>
		<description><![CDATA[<br /><p>One of the really nice features I enjoy using in Resharper 4.0 is the refactoring that converts inefficient (and unpleasant to read) syntax into nice efficient code.  In this post, I'll show some refactorings that Resharper (from JetBrains) gives us.  There are lots more, but the ones listed below seem to come up the most in my own c# code.</p><br />]]></description>
			<content:encoded><![CDATA[<p>One of the really nice features I enjoy using in <a href="http://www.jetbrains.com/resharper/" target="_blank">Resharper 4.0</a> is the refactoring that converts inefficient (and unpleasant to read) syntax into nice efficient code.&#160; In this post, I&#8217;ll show some refactorings that Resharper (from <a href="http://www.jetbrains.com/index.html" target="_blank">JetBrains</a>) gives us.&#160; There are lots more, but the ones listed below seem to come up the most in my own c# code.</p> <span id="more-121"></span>  <h2>Creates String.Format in C# From &quot;a&quot; + &quot;b&quot; + &quot;c&quot; syntax</h2>  <p>From:</p>  <pre class="csharpcode">var url = wikiURL + <span class="str">&quot;/api/AddPage?apikey_v1=&quot;</span> + apiKey
                                + <span class="str">&quot;&amp;page=&quot;</span> + wikiPageName
                                + <span class="str">&quot;&amp;name=&quot;</span> + name
                                + <span class="str">&quot;&amp;email=&quot;</span> + email; </pre>

<p>
  <br /></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>To:</p>

<pre class="csharpcode">var url =  <span class="kwrd">string</span>.Format(<span class="str">&quot;{0}/api/AddPage?apikey_v1={1}&amp;page={2}&amp;name={3}&amp;email={4}&quot;</span>,
                    wikiURL, apiKey, wikiPageName, name, email); </pre>

<p>
  <br /></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>&#160;</p>

<h2>Create Simple Logical Assignments From my Overly Verbose Code</h2>

<p>From:</p>

<pre class="csharpcode"><span class="kwrd">if</span> (ConfigurationManager.AppSettings[<span class="str">&quot;ShowDinnerConfirmation&quot;</span>].ToLower().Equals(<span class="str">&quot;true&quot;</span>))
            {
                TableRowSaturdayDinner.Visible = <span class="kwrd">true</span>;
            }
            <span class="kwrd">else</span>
            {
                TableRowSaturdayDinner.Visible = <span class="kwrd">false</span>;
            } </pre>

<p>
  <br /></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>&#160;</p>

<p>To:</p>

<pre class="csharpcode">TableRowSaturdayDinner.Visible = ConfigurationManager.AppSettings[<span class="str">&quot;ShowDinnerConfirmation&quot;</span>].ToLower().Equals(<span class="str">&quot;true&quot;</span>); </pre>

<p>
  <br /></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>&#160;</p>

<h2>Use ?? When I&#8217;ve used Simple ? Operator Makes for Simpler Code</h2>

<p>From:</p>

<pre class="csharpcode"><span class="kwrd">string</span> s = context.Request.QueryString[<span class="str">&quot;Cache&quot;</span>] == <span class="kwrd">null</span> ? <span class="str">&quot;true&quot;</span> : context.Request.QueryString[<span class="str">&quot;Cache&quot;</span>];</pre>

<p>
  <br /></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>To:</p>

<pre class="csharpcode"><span class="kwrd">string</span> s = context.Request.QueryString[<span class="str">&quot;Cache&quot;</span>] ?? <span class="str">&quot;true&quot;</span>;</pre>

<p>
  <br /></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/07/03/code-refactoring-with-resharper/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a Modal Login Window Using the Telerik Modal RadWindow ComponentBuilding the Code Camp Web Site (Article 4)</title>
		<link>http://peterkellner.net/2008/06/29/sv-code-camp-web-site-series4/</link>
		<comments>http://peterkellner.net/2008/06/29/sv-code-camp-web-site-series4/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 15:47:43 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Code Camp Web Site Series]]></category>
		<category><![CDATA[How Things Work]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=286</guid>
		<description><![CDATA[<br /><p>This article shows how to create a modal windows (not a popup) that displays a login windows (asking for username and password) in the middle of whatever asp.net page you are viewing.  It uses the Telerik Modal Radwindow control.  At the end of a successful login, the login dialog redirects the web user to some page designated by the author.  It requires no Javascript programming by the programmer.  Just simple method calls in the asp.net page.</p>]]></description>
			<content:encoded><![CDATA[<h3>Article Series</h3> <table border="0" cellspacing="0" cellpadding="2"><tbody>     <tr>       <td valign="top" width="100">Article 1:</td>        <td valign="top" width="600"><a href="/2008/05/13/codecampwebsiteseries1/">Best Practices for Building an ASP.NET quality web site</a></td>     </tr>      <tr>       <td>Article 2:</td>        <td><a href="/2008/05/19/codecampwebsiteseries2/">Multi Level ASP.NET Menu with CSS Friendly Control Adapters</a></td>     </tr>      <tr>       <td>Article 3:</td>        <td><a href="/2008/05/25/codecampwebsiteseries3/">Creating a Theme For Each Year of Code Camp Using Skins in ASP.NET</a></td>     </tr>      <tr>       <td>Article 4:</td>        <td><a href="/2008/06/29/sv-code-camp-web-site-series4/">Creating a Modal Login Window Using the Telerik Modal RadWindow Component</a></td>     </tr>      <tr>       <td>Article 5:</td>        <td><a href="/2008/07/03/combine-email-lists-with-linq/">Using LINQ to Merge Mailing Lists and Filter Opt Outs</a></td>     </tr>     <tr>       <td>Article 6:</td>        <td><a href="/2009/03/27/codecampwebsiteseries6-cssfriendly-adapters-aspnet-menu/">Multi Level ASP.NET Menu with CSS Friendly Control Adapters (The Source Code!)</a></td>     </tr>   </tbody></table> <br /> <h2>Introduction</h2> <p>This article shows how to create a modal windows (not a popup) that displays a login windows (asking for username and password) in the middle of whatever <a href="http://www.asp.net/">asp.net</a> page you are viewing.&#160; It uses the <a href="http://www.telerik.com/products/aspnet-ajax/controls/window/overview.aspx">Telerik Modal Radwindow</a> control.&#160; At the end of a successful login, the login dialog redirects the web user to some page designated by the author.&#160; It requires no <a href="http://www.javascript.com/">Javascript</a> programming by the programmer.&#160; Just simple method calls in the <a href="http://www.asp.net/">asp.net</a> page.</p> <p> <span id="more-118"></span> </p> <h2>How it Looks to the Web User</h2> <p>When the user press the login button in the upper right corner of the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp web site</a>, below is the screen they see.</p> <p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/06/test.png">     <br /> <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="test" src="http://peterkellner.net/wp/wp-content/uploads/2008/06/test-thumb.png" width="384" height="332" /></a></p> <p>Notice that the screen behind actually fades out and is not able to be clicked by the web user.</p> <h2>The Method Behind Creating the Modal Window</h2> <p>OK, so there is a little bit of javascript you need to add to your page.&#160; Basically, what you do is in your master page, around where you have your login control, you put the following code into your aspx page.</p> <div class="csharpcode"> <pre><span class="kwrd"></span></pre>
</div>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span> <span class="kwrd">&lt;</span><span class="html">asp:ScriptManager</span> <span class="attr">ID</span><span class="kwrd">=&quot;ScriptManager1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">EnablePartialRendering</span><span class="kwrd">=&quot;true&quot;</span> <span class="kwrd">/&gt;</span></pre>

<pre><span class="lnum">   2:  </span>    <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">class</span><span class="kwrd">=&quot;headBar&quot;</span> <span class="attr">cellpadding</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">cellspacing</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">   4:  </span>            <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">   5:  </span>                <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;headLogo&quot;</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">   6:  </span>                <span class="kwrd">&lt;</span><span class="html">asp:HyperLink</span> <span class="attr">ID</span><span class="kwrd">=&quot;HomeLink&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">NavigateUrl</span><span class="kwrd">=&quot;Default.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">   7:  </span>                    <span class="kwrd">&lt;</span><span class="html">asp:Image</span> <span class="attr">ID</span><span class="kwrd">=&quot;HeadLogo&quot;</span> <span class="attr">SkinID</span><span class="kwrd">=&quot;ImageLogo&quot;</span> <span class="attr">AlternateText</span><span class="kwrd">=&quot;Silicon Valley codecamp_08&quot;</span></pre>

<pre><span class="lnum">   8:  </span>                        <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="kwrd">/&gt;</span></pre>

<pre class="alt"><span class="lnum">   9:  </span>                <span class="kwrd">&lt;/</span><span class="html">asp:HyperLink</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  10:  </span>                </pre>

<pre class="alt"><span class="lnum">  11:  </span>               </pre>

<pre><span class="lnum">  12:  </span>                </pre>

<pre class="alt"><span class="lnum">  13:  </span>                <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  14:  </span>            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  15:  </span>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">valign</span><span class="kwrd">=&quot;middle&quot;</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  16:  </span>                <span class="kwrd">&lt;</span><span class="html">span</span> <span class="attr">class</span><span class="kwrd">=&quot;headDate&quot;</span><span class="kwrd">&gt;</span>Saturday and Sunday, November 8th &amp; 9th, 2008<span class="kwrd">&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  17:  </span>            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  18:  </span>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">align</span><span class="kwrd">=&quot;right&quot;</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  19:  </span>                <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;headLogin&quot;</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  20:  </span>                    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  21:  </span> </pre>

<pre><span class="lnum">  22:  </span>                        <span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">=&quot;text/javascript&quot;</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  23:  </span>                            <span class="rem">//&lt;![CDATA[</span></pre>

<pre><span class="lnum">  24:  </span>                            <span class="rem">//show the window</span></pre>

<pre class="alt"><span class="lnum">  25:  </span>                            <span class="kwrd">function</span> showDialog()</pre>

<pre><span class="lnum">  26:  </span>                            {                    </pre>

<pre class="alt"><span class="lnum">  27:  </span>                                <span class="rem">//Force reload in order to guarantee that the onload event handler </span></pre>

<pre><span class="lnum">  28:  </span>                                <span class="rem">// of the dialog which configures it executes on every show.</span></pre>

<pre class="alt"><span class="lnum">  29:  </span>                                <span class="kwrd">var</span> oWnd = window.radopen(<span class="kwrd">null</span>, <span class="str">&quot;DialogWindow&quot;</span>);</pre>

<pre><span class="lnum">  30:  </span>                                oWnd.setUrl(oWnd.get_navigateUrl());</pre>

<pre class="alt"><span class="lnum">  31:  </span>                            }</pre>

<pre><span class="lnum">  32:  </span>                            </pre>

<pre class="alt"><span class="lnum">  33:  </span>                           </pre>

<pre><span class="lnum">  34:  </span>                            <span class="rem">// Called when a window is being closed.  (force refresh)</span></pre>

<pre class="alt"><span class="lnum">  35:  </span>                            <span class="kwrd">function</span> OnClientclose(radWindow)</pre>

<pre><span class="lnum">  36:  </span>                            {     </pre>

<pre class="alt"><span class="lnum">  37:  </span>                                 window.location.href = <span class="str">&quot;News.aspx&quot;</span>;           </pre>

<pre><span class="lnum">  38:  </span>                            }    </pre>

<pre class="alt"><span class="lnum">  39:  </span>                            <span class="rem">//]]&gt;            </span></pre>

<pre><span class="lnum">  40:  </span>                        <span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  41:  </span> </pre>

<pre><span class="lnum">  42:  </span>                        <span class="kwrd">&lt;</span><span class="html">asp:ImageButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;IDLoginButton&quot;</span> <span class="attr">SkinID</span><span class="kwrd">=&quot;ButtonLogin&quot;</span> </pre>

<pre class="alt"><span class="lnum">  43:  </span>                            <span class="attr">OnClientClick</span><span class="kwrd">=&quot;showDialog();return false;&quot;</span></pre>

<pre><span class="lnum">  44:  </span>                            <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="kwrd">/&gt;</span>   </pre>

<pre class="alt"><span class="lnum">  45:  </span>                        <span class="kwrd">&lt;</span><span class="html">asp:LoginStatus</span> <span class="attr">ID</span><span class="kwrd">=&quot;IDLoginStatus1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="kwrd">/&gt;</span></pre>

<pre><span class="lnum">  46:  </span>                        <span class="kwrd">&lt;</span><span class="html">asp:LoginName</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">ID</span><span class="kwrd">=&quot;IDLoginName1&quot;</span> <span class="kwrd">/&gt;</span></pre>

<pre class="alt"><span class="lnum">  47:  </span>                        <span class="kwrd">&lt;</span><span class="html">telerik:RadWindowManager</span> <span class="attr">ID</span><span class="kwrd">=&quot;Singleton&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  48:  </span>                            <span class="kwrd">&lt;</span><span class="html">Windows</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  49:  </span>                                <span class="kwrd">&lt;</span><span class="html">telerik:RadWindow</span> <span class="attr">ID</span><span class="kwrd">=&quot;DialogWindow&quot;</span> <span class="attr">Behaviors</span><span class="kwrd">=&quot;Close&quot;</span> </pre>

<pre><span class="lnum">  50:  </span>                                    <span class="attr">ReloadOnShow</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">OnClientClose</span><span class="kwrd">=&quot;OnClientclose&quot;</span></pre>

<pre class="alt"><span class="lnum">  51:  </span>                                    <span class="attr">BackColor</span><span class="kwrd">=&quot;Gray&quot;</span> <span class="attr">Modal</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">Height</span><span class="kwrd">=&quot;250&quot;</span> </pre>

<pre><span class="lnum">  52:  </span>                                    <span class="attr">NavigateUrl</span><span class="kwrd">=&quot;./Login.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  53:  </span>                                <span class="kwrd">&lt;/</span><span class="html">telerik:RadWindow</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  54:  </span>                            <span class="kwrd">&lt;/</span><span class="html">Windows</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  55:  </span>                        <span class="kwrd">&lt;/</span><span class="html">telerik:RadWindowManager</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  56:  </span>                        </pre>

<pre class="alt"><span class="lnum">  57:  </span>                        <span class="kwrd">&lt;</span><span class="html">asp:HyperLink</span> <span class="attr">ID</span><span class="kwrd">=&quot;HyperLinkForgotChangePassword&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> </pre>

<pre><span class="lnum">  58:  </span>                             <span class="attr">NavigateUrl</span><span class="kwrd">=&quot;~/PasswordIssues.aspx&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Forgot Password?&quot;</span> <span class="kwrd">&gt;&lt;/</span><span class="html">asp:HyperLink</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  59:  </span>                        </pre>

<pre><span class="lnum">  60:  </span>                    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  61:  </span>                    </pre>

<pre><span class="lnum">  62:  </span>                <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="lnum">  63:  </span>            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

<pre><span class="lnum">  64:  </span>        <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>
</div>
<p>Line 22 to 40 shows the javascript.&#160; Basically, you are calling the Telerik window.radopen method which is associated with the tag on line 49.&#160; It automatically navigates to the login.aspx page which is referenced in line 52.&#160; When the page closes, the javascript on line 37 tells the browser to redirect to the News.aspx page.&#160; The reason I do this is because if you don&#8217;t change pages, I&#8217;ve found the the login cookie is not set (Authorization cookie).&#160; When this happens, even though the person is logged in, they do not see that they are until a page refresh happens.&#160; Very confusing to the user.</p>
<h2>Conclusions</h2>
<p>That is really all this is to adding a windows that displays in the middle of your page.&#160; It&#8217;s so much nicer than having to send the user to a separate page to login.&#160; They can see where they are as they are logging in.&#160; I hope this helps you.&#160; I find it a very useful technique I can use in lots of web sites.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/06/29/sv-code-camp-web-site-series4/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Creating a Theme For Each Year of Code Camp Using Skins in ASP.NETBuilding the New Code Camp Web Site (Part 3)</title>
		<link>http://peterkellner.net/2008/05/25/codecampwebsiteseries3/</link>
		<comments>http://peterkellner.net/2008/05/25/codecampwebsiteseries3/#comments</comments>
		<pubDate>Sun, 25 May 2008 22:17:56 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Code Camp Web Site Series]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/05/25/codecampwebsiteseries3/</guid>
		<description><![CDATA[<p>In this post, we discuss how to use themes and skins together in an ASP.NET web site.  A complete example is shown including the web.config, a master page and the theme.skin file.  This is an ongoing series of the trials and tribulations of building a new code camp web site.</p>]]></description>
			<content:encoded><![CDATA[<h2>Article Series</h2> <table border="0" cellspacing="0" cellpadding="2"><tbody>     <tr>       <td valign="top" width="100">Article 1:</td>        <td valign="top" width="600"><a href="/2008/05/13/codecampwebsiteseries1/" target="_blank">Best Practices for Building an ASP.NET quality web site</a></td>     </tr>      <tr>       <td>Article 2:</td>        <td><a href="/2008/05/19/codecampwebsiteseries2/">Multi Level ASP.NET Menu with CSS Friendly Control Adapters</a></td>     </tr>      <tr>       <td>Article 3:</td>        <td><a href="/2008/05/25/codecampwebsiteseries3/">Creating a Theme For Each Year of Code Camp Using Skins in ASP.NET</a></td>     </tr>      <tr>       <td>Article 4:</td>        <td><a href="/2008/06/29/sv-code-camp-web-site-series4/">Creating a Modal Login Window Using the Telerik Modal RadWindow Component</a></td>     </tr>      <tr>       <td>Article 5:</td>        <td><a href="/2008/07/03/combine-email-lists-with-linq/">Using LINQ to Merge Mailing Lists and Filter Opt Outs</a></td>     </tr>     <tr>       <td>Article 6:</td>        <td><a href="/2009/03/27/codecampwebsiteseries6-cssfriendly-adapters-aspnet-menu/">Multi Level ASP.NET Menu with CSS Friendly Control Adapters (The Source Code!)</a></td>     </tr>   </tbody></table> <br /> <h2>Introduction</h2> <p>Creating themes for ASP.NET 2.0 is very easy if you follow the standard guidelines Microsoft gives us.&#160; Microsoft gives a pretty good discussion in the MSDN article    <br /> <a href="http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx">ASP.NET Themes and Skins Overview</a>.&#160; I&#8217;ve read it several times but since I don&#8217;t do this very often I keep forgetting the simple things.&#160; Recently,     <br /> <a href="http://forums.asp.net/t/1265904.aspx">I posted a question on ASP.NET forums</a> asking how to have an image automatically come from the correct theme directory.&#160; As usual, <a href="http://blogs.ipona.com/davids/Default.aspx">Dave Sussman</a>     <br /> gave me the perfect answer.</p> <p><em>&quot;You should store the images under the themes and set the ImageUrl in the skin file. Give the control a SkinID in both the skin file and in the page. When the theme changes the appropriate image will be used.&quot;</em></p> <p>In this article, I&#8217;ll basically explain his answer with an example using the code camp web site.</p> <p> <span id="more-114"></span> </p> <h2>Code Camp Site Structure</h2> <p>The Code Camp project has a very standard directory setup.&#160; In Visual Studio 2008, the solution explorer looks like this:    <br /> <a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/solu.png">     <br /> <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="solu" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/solu-thumb.png" width="372" height="301" /></a></p> <p>Notice that I have two themes defined, Gray2008 and Gray2009.&#160; The reason for this is so when 2009 comes along and we want to change certain images that contain things like the Code Camp Date and Year, we don&#8217;t have to do surgery on the asp.net pages, but simply change to the new theme and update the files there.&#160; This also keeps the code base intact so we don&#8217;t have to branch our code for next year.&#160; All in all, a very clean solution.</p> <h2>The Mechanics of Theme Changing and the Skin Definitions</h2> <p>First, you have simple mention in your web.config file the name of the default theme you will be using.&#160; By doing that, it references the correct App_Themes sub directory. Our web.config looks like the following for this year which means we will be using the Gray2009 theme directory.</p> <p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/webconfigtheme.png">     <br /> <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="webconfigtheme" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/webconfigtheme-thumb.png" width="479" height="73" /></a></p> <p>Second, you need to mention a SkinId in any control you may use.&#160; In our case, we want to have the image on the upper right side of the code camp web site display the correct year.&#160; That is, on the home page we have something like this:</p> <p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/actualpngforcc.png">     <br /> <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="actualpngforcc" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/actualpngforcc-thumb.png" width="498" height="134" /></a></p> <p>The tag in the master page looks like this:</p> <p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/imagetag.png">     <br /> <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="imagetag" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/imagetag-thumb.png" width="577" height="100" /></a></p> <p>Notice the SkinId circled in green.&#160; Also notice that there is no ImageUrl defined in this tag.&#160; What happens next is that web site will look in the default theme&#8217;s SkinFile.skin file (see the solution explorer above for this).&#160; In the App_Themes/Gray2008/SkinFile.skin file there is a reference that finds the actual image file that will be used.&#160; It reference it from the App_THemes/Gray2008/Images directory as follows:</p> <p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/skinfile.png">     <br /> <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="skinfile" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/skinfile-thumb.png" width="586" height="108" /></a></p> <p>And, that&#8217;s it!&#160; Just by changing the theme in the web.config file, the correct image file will be displayed in the master page.&#160; The other nice thing is that design time support works also.&#160; You will see in the Visual Studio 2008 Designer the correct image based on where your web.config points.</p> <h2>Conclusion</h2> <p>In this article, we&#8217;ve shown the details of how to have a flexible design that    <br /> supports multiple theme files.&#160; Something we will use for years and years with     <br /> the new Code Camp web site.&#160; We also may decide to have different themes for     <br /> different types of users.&#160; That is, admin&#8217;s may have a different theme than     <br /> normal users.&#160; We could also let users pick there own color styles by having     <br /> different themes.&#160; Lots of possibilities.</p> <p>I hope this helps you.</p> <p>&#160;</p> <style type="text/css">


.csharpcode, .csharpcode pre {
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre {
	margin: 0em;
}
.csharpcode .rem {
	color: #008000;
}
.csharpcode .kwrd {
	color: #0000ff;
}
.csharpcode .str {
	color: #006080;
}
.csharpcode .op {
	color: #0000c0;
}
.csharpcode .preproc {
	color: #cc6633;
}
.csharpcode .asp {
	background-color: #ffff00;
}
.csharpcode .html {
	color: #800000;
}
.csharpcode .attr {
	color: #ff0000;
}
.csharpcode .alt {
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum {
	color: #606060;
}</style>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/05/25/codecampwebsiteseries3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Multi Level ASP.NET Menu with CSS Friendly Control AdaptersBuilding the New Code Camp Web Site (Part 2)</title>
		<link>http://peterkellner.net/2008/05/19/codecampwebsiteseries2/</link>
		<comments>http://peterkellner.net/2008/05/19/codecampwebsiteseries2/#comments</comments>
		<pubDate>Mon, 19 May 2008 22:38:46 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[CSS Adapters]]></category>
		<category><![CDATA[Code Camp Web Site Series]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/05/19/codecampwebsiteseries2/</guid>
		<description><![CDATA[<p>This article discusses the CSS Friendly Adapters and how they are integraged with the ASP.NET 2.0 menu control.  It shows the default html created by a sample menu control without the Friendly Adapters, as well as showing the html created using the Friendly Adapters.</p>]]></description>
			<content:encoded><![CDATA[<h2>Article Series</h2>

<blockquote>
  <p><strong><em>(Source Code Available in Article 6 Below &#8211; (Added March 2009))</em></strong></p>
</blockquote>

<table border="0" cellspacing="0" cellpadding="2"><tbody>
    <tr>
      <td valign="top" width="100">Article 1:</td>

      <td valign="top" width="600"><a href="/2008/05/13/codecampwebsiteseries1/" target="_blank">Best Practices for Building an ASP.NET quality web site</a></td>
    </tr>

    <tr>
      <td>Article 2:</td>

      <td><a href="/2008/05/19/codecampwebsiteseries2/">Multi Level ASP.NET Menu with CSS Friendly Control Adapters</a></td>
    </tr>

    <tr>
      <td>Article 3:</td>

      <td><a href="/2008/05/25/codecampwebsiteseries3/">Creating a Theme For Each Year of Code Camp Using Skins in ASP.NET</a></td>
    </tr>

    <tr>
      <td>Article 4:</td>

      <td><a href="/2008/06/29/sv-code-camp-web-site-series4/">Creating a Modal Login Window Using the Telerik Modal RadWindow Component</a></td>
    </tr>

    <tr>
      <td>Article 5:</td>

      <td><a href="/2008/07/03/combine-email-lists-with-linq/">Using LINQ to Merge Mailing Lists and Filter Opt Outs</a></td>
    </tr>

    <tr>
      <td>Article 6:</td>

      <td><a href="/2009/03/27/codecampwebsiteseries6-cssfriendly-adapters-aspnet-menu/">Multi Level ASP.NET Menu with CSS Friendly Control Adapters (The Source Code!)</a></td>
    </tr>
  </tbody></table>

<br />

<h2>Introduction</h2>

<div>
  <div class="peterkellnerpromo">If you have complex styling issues involving ASP.NET we are experts and might be able to help.  This technique is fairly old however newer methods could be used for similar results. Contact Peter Kellner and his associates <a href="http://peterkellner.net/contactus">here</a>. </div>

  <div>
    <p>It&#8217;s often the case that brilliant designers will make interfaces that are hard to implement using standard frameworks like ASP.NET.&#160; As Software engineers striving for consistency, we always want to do the best we can with the standard tool kits to take advantage for built in functionality.&#160; <a href="http://asp.net/" target="_blank">ASP.NET 2.0&#8217;s</a> built in menu system is a perfect example.&#160; If you use that menu system, you get to make very simple declarative site maps by simply using the <a href="http://weblogs.asp.net/scottgu/archive/2005/11/20/431019.aspx">ASP.NET 2.0 Site Navigation Features.</a></p>

    <p>The requirement faced today has to do with building the web site for our <a href="http://www.siliconvalley-codecamp.com/" target="_blank">third annual code camp</a>.&#160; We have that brilliant designer I mentioned above, and he has made a design that just seems too perfect to compromise.&#160; Here are some screen shots of how the designer envisions the sight looking and working after it is completed.</p>
  </div>

  
<span id="more-112"></span>


  <table border="0" cellspacing="0" cellpadding="2" width="800"><tbody>
      <tr>
        <td valign="top" width="800">
          <br /><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/css1.jpg">
            <br /><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="css1" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/css1-thumb.jpg" width="740" height="133" /></a> 

          <br /></td>
      </tr>

      <tr>
        <td valign="top" width="800">
          <br /><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/css2.jpg">
            <br /><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="css2" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/css2-thumb.jpg" width="741" height="121" /></a> 

          <br /></td>
      </tr>

      <tr>
        <td valign="top" width="800">
          <br /><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/css3.jpg">
            <br /><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="css3" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/css3-thumb.jpg" width="740" height="136" /></a> 

          <br /></td>
      </tr>

      <tr>
        <td valign="top" width="800">
          <br /><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/css4.jpg">
            <br /><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="css4" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/css4-thumb.jpg" width="741" height="124" /></a> 

          <br /></td>
      </tr>

      <tr>
        <td valign="top" width="800">
          <br /><a href="http://peterkellner.net/wp/wp-content/uploads/2008/05/css5.jpg">
            <br /><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="css5" src="http://peterkellner.net/wp/wp-content/uploads/2008/05/css5-thumb.jpg" width="748" height="134" /></a> 

          <br /></td>
      </tr>
    </tbody></table>

  <p>Notice the interesting behavior of the top menu (REGISTER;PROGRAM;NEWS;ABOUT AND WIKI).&#160; Unselected, the bottom line strip is the same as selected.&#160; When selected, the background of the selection changes to a different shade of the same color as the bottom strip.</p>

  <p>Also notice the interesting behavior of the secondary menu. that is, when ABOUT is selected from the top menu, notice that the secondary menu shows: Contact;Venue;Organizers;Sponsors and Previous.&#160; As you can see above (on the bottom of the 5 pictures), when Venu is selected, it is highlighted to in bright white to indicate that you have selected that.&#160; The really cool part here is that the ABOUT on the primary menu stays highlighted when you choose different&#160; secondary menu choices.</p>

  <h2>Why Go Through The Trouble, why not just do it with HTML and CSS directly</h2>

  <p>So, a reasonable person might say that since you can&#8217;t easily get this behavior with the asp:menu control and the site map provider (OK, at least I couldn&#8217;t figure it out), why not just code this up with simple list items, button clicks and a pile of code to react to those things?&#160; Well, the answer is you can certainly do that.&#160; The problem is the next time you want to do something similar you will find yourself doing a lot of cut and pasting.&#160; Personally, whenever I find myself cutting and pasting a lot I know I should probably think about how to refactor the code to make it more reusable and therefore more reliable.</p>

  <h2>What Are the Benefits of Using asp:menu and the site map providers </h2>

  <p>I mentioned that there are benefits to using the asp:menu and site map providers.&#160; What are those benefits you might ask.&#160; Well, let me first show you what you have to do to set up a simple menu system using these, then list the benefits of what comes out.</p>

  <h3>The Web.SiteMap</h3>

  <p>First, you need to create a web.sitemap file in your web directory.&#160; Here is what a simple one looks like similar to what will create the pictures above.</p>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span> <span class="attr">encoding</span><span class="kwrd">=&quot;utf-8&quot;</span> ?<span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>   <span class="kwrd">&lt;</span><span class="html">siteMap</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://schemas.microsoft.com/AspNet/SiteMap-File-1.0&quot;</span> <span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;Default.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;HOME&quot;</span> <span class="attr">description</span><span class="kwrd">=&quot;Silicon Valley CodeCamp 08&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;Register.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;REGISTER&quot;</span>  <span class="attr">description</span><span class="kwrd">=&quot;&quot;</span> <span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;News.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;NEWS&quot;</span>  <span class="attr">description</span><span class="kwrd">=&quot;&quot;</span> <span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;About.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;ABOUT&quot;</span>  <span class="attr">description</span><span class="kwrd">=&quot;&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;Contact.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;Contact&quot;</span>  <span class="attr">description</span><span class="kwrd">=&quot;&quot;</span> <span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;Sponsors.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;Sponsors&quot;</span>  <span class="attr">description</span><span class="kwrd">=&quot;&quot;</span> <span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">url</span><span class="kwrd">=&quot;Previous.aspx&quot;</span> <span class="attr">title</span><span class="kwrd">=&quot;Previous&quot;</span>  <span class="attr">description</span><span class="kwrd">=&quot;&quot;</span> <span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre>         <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">      <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>   <span class="kwrd">&lt;/</span><span class="html">siteMap</span><span class="kwrd">&gt;</span></pre>
  </div>

  <h3>The Web.Config </h3>

  <p>You need to declare which sitemap provider you are using. In our case, we are simply reading from a file.&#160; Then, you should (do not have to) declare a section for each web page you want to provide role access to.&#160; Here is an example of my web.config. This first part says give access to any logged in user for Sponsors.aspx</p>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">&lt;</span><span class="html">location</span> <span class="attr">path</span><span class="kwrd">=&quot;Sponsors.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;</span><span class="html">system.web</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="kwrd">&lt;</span><span class="html">authorization</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">deny</span> <span class="attr">users</span><span class="kwrd">=&quot;?&quot;</span><span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">authorization</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;/</span><span class="html">system.web</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt"><span class="kwrd">&lt;/</span><span class="html">location</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre><span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>
  </div>

  <p>The Second part defines the Site Map Provider and sets securityTrimming to true to only show pages the user has access to.</p>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">&lt;</span><span class="html">system.web</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;</span><span class="html">siteMap</span> <span class="attr">defaultProvider</span><span class="kwrd">=&quot;XmlSiteMapProvider&quot;</span> <span class="attr">enabled</span><span class="kwrd">=&quot;true&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">    <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;XmlSiteMapProvider&quot;</span> </pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="attr">description</span><span class="kwrd">=&quot;SiteMap provider which reads in .sitemap XML files.&quot;</span> </pre>

    <p>&#160;</p>

    <pre>        <span class="attr">type</span><span class="kwrd">=&quot;System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0,... </pre>

    <p>&#160;</p>

    <pre class="alt">        siteMapFile=&quot;</span><span class="attr">web</span>.<span class="attr">sitemap</span><span class="kwrd">&quot; securityTrimmingEnabled=&quot;</span><span class="attr">true</span>&quot;<span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">    <span class="kwrd">&lt;/</span><span class="html">siteMap</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>&#160;</pre>
  </div>

  <h3>The Master Page</h3>

  <p>In your master page, you need to define your primary menu.&#160; In our case, it is the one that displays: REGISTER;NEWS and ABOUT.&#160; Here is all you need for that.</p>

  <div class="csharpcode">
    <pre class="alt">    <span class="kwrd">&lt;</span><span class="html">asp:Menu</span> <span class="attr">ID</span><span class="kwrd">=&quot;mainMenu&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">Orientation</span><span class="kwrd">=&quot;Horizontal&quot;</span> </pre>

    <p>&#160;</p>

    <pre>        <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SiteMapMain&quot;</span> <span class="attr">CssClass</span><span class="kwrd">=&quot;headLinksBar&quot;</span>  <span class="attr">CssSelectorClass</span><span class="kwrd">=&quot;SimpleEntertainmentMenu&quot;</span></pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="attr">MaximumDynamicDisplayLevels</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">StaticItemFormatString</span><span class="kwrd">=&quot;// {0} &amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;/</span><span class="html">asp:Menu</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt"><span class="kwrd">&lt;</span><span class="html">asp:SiteMapDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;SiteMapMain&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">ShowStartingNode</span><span class="kwrd">=&quot;False&quot;</span> <span class="kwrd">/&gt;</span></pre>
  </div>

  <h3>The Inherited Page (About.aspx For Example)</h3>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">&lt;</span><span class="html">asp:Content</span> <span class="attr">ID</span><span class="kwrd">=&quot;SublinksSessions&quot;</span> <span class="attr">ContentPlaceHolderID</span><span class="kwrd">=&quot;Sublinks&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;</span><span class="html">asp:Menu</span> <span class="attr">ID</span><span class="kwrd">=&quot;subMenu&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SiteMapAbout&quot;</span> <span class="attr">SkinID</span><span class="kwrd">=&quot;subMenu&quot;</span>  <span class="attr">CssClass</span><span class="kwrd">=&quot;headLinksBar&quot;</span> </pre>

    <p>&#160;</p>

    <pre class="alt">    <span class="attr">CssSelectorClass</span><span class="kwrd">=&quot;SimpleEntertainmentMenu&quot;</span>     <span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;/</span><span class="html">asp:Menu</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt"><span class="kwrd">&lt;/</span><span class="html">asp:Content</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>&#160;</pre>
  </div>

  <h3>And the Benefits&#8230;</h3>

  <ul>
    <li>You have no .net code to write! </li>

    <li>Adding new menu items as Primary or Secondary is easy </li>

    <li>Security is completely taken care of </li>

    <li>Menu Entries Automatically come and go based on User Permission&#160; </li>
  </ul>

  <h2>Not Using the <a href="http://www.codeplex.com/cssfriendly" target="_blank">
      <p>CSS Friendly Adapters</p>
    </a></h2>

  <p>If you do not use the CSS Friendly Adapter library, the menu render using tables.&#160; <br />Below is what the actual HTML looks like of the main menu if I remove the</p>

  <p><a href="http://www.codeplex.com/cssfriendly" target="_blank">CSS Friendly Adapters</a>.</p>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">&lt;</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">=&quot;#ctl00_mainMenu_SkipLink&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="kwrd">&lt;</span><span class="html">img</span> <span class="attr">alt</span><span class="kwrd">=&quot;Skip Navigation Links&quot;</span> <span class="attr">src</span><span class="kwrd">=&quot;/WebStyleOnly%20-%20Copy/WebResource.axd?d=G5&quot;</span> <span class="attr">width</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">height</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">style</span><span class="kwrd">=&quot;border-width: 0px;&quot;</span> <span class="kwrd">/&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">    <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">id</span><span class="kwrd">=&quot;ctl00_mainMenu&quot;</span> <span class="attr">class</span><span class="kwrd">=&quot;headLinksBar ctl00_mainMenu_2&quot;</span> <span class="attr">cssselectorclass</span><span class="kwrd">=&quot;SimpleEntertainmentMenu&quot;</span> <span class="attr">cellpadding</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">cellspacing</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">border</span><span class="kwrd">=&quot;0&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>        <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">onmouseover</span><span class="kwrd">=&quot;Menu_HoverStatic(this)&quot;</span> <span class="attr">onmouseout</span><span class="kwrd">=&quot;Menu_Unhover(this)&quot;</span> <span class="attr">onkeyup</span><span class="kwrd">=&quot;Menu_Key(this)&quot;</span> <span class="attr">id</span><span class="kwrd">=&quot;ctl00_mainMenun0&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">cellpadding</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">cellspacing</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">border</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">width</span><span class="kwrd">=&quot;100%&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">=&quot;white-space: nowrap;&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                            <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">class</span><span class="kwrd">=&quot;ctl00_mainMenu_1&quot;</span> <span class="attr">href</span><span class="kwrd">=&quot;/WebStyleOnly%20-%20Copy/Register.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                                // REGISTER</pre>

    <p>&#160;</p>

    <pre class="alt">                            <span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">=&quot;width: 3px;&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">onmouseover</span><span class="kwrd">=&quot;Menu_HoverStatic(this)&quot;</span> <span class="attr">onmouseout</span><span class="kwrd">=&quot;Menu_Unhover(this)&quot;</span> <span class="attr">onkeyup</span><span class="kwrd">=&quot;Menu_Key(this)&quot;</span> <span class="attr">id</span><span class="kwrd">=&quot;ctl00_mainMenun1&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">cellpadding</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">cellspacing</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">border</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">width</span><span class="kwrd">=&quot;100%&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">=&quot;white-space: nowrap;&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">class</span><span class="kwrd">=&quot;ctl00_mainMenu_1&quot;</span> <span class="attr">href</span><span class="kwrd">=&quot;/WebStyleOnly%20-%20Copy/News.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                            // NEWS </pre>

    <p>&#160;</p>

    <pre>                        <span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">=&quot;width: 3px;&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">onmouseover</span><span class="kwrd">=&quot;Menu_HoverStatic(this)&quot;</span> <span class="attr">onmouseout</span><span class="kwrd">=&quot;Menu_Unhover(this)&quot;</span> <span class="attr">onkeyup</span><span class="kwrd">=&quot;Menu_Key(this)&quot;</span> <span class="attr">id</span><span class="kwrd">=&quot;ctl00_mainMenun2&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">cellpadding</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">cellspacing</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">border</span><span class="kwrd">=&quot;0&quot;</span> <span class="attr">width</span><span class="kwrd">=&quot;100%&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">=&quot;white-space: nowrap;&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                            <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">class</span><span class="kwrd">=&quot;ctl00_mainMenu_1&quot;</span> <span class="attr">href</span><span class="kwrd">=&quot;/WebStyleOnly%20-%20Copy/About.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                                // ABOUT</pre>

    <p>&#160;</p>

    <pre class="alt">                            <span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre><span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>
  </div>

  <p>The same code, when using the <a href="http://www.codeplex.com/cssfriendly" target="_blank">CSS Friendly adapters</a>, plus some clever additions that will be discussed later, has the html code looking like the following.</p>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">&lt;</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">        <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;AspNet-Menu-Horizontal&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>            <span class="kwrd">&lt;</span><span class="html">ul</span> <span class="attr">class</span><span class="kwrd">=&quot;AspNet-Menu&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                <span class="kwrd">&lt;</span><span class="html">li</span> <span class="attr">class</span><span class="kwrd">=&quot;AspNet-Menu-TopLevel-register&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                    <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">=&quot;/WebStyleOnly - Copy/Register.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                      REGISTER</pre>

    <p>&#160;</p>

    <pre>                     <span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span> </pre>

    <p>&#160;</p>

    <pre class="alt">                <span class="kwrd">&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                 <span class="kwrd">&lt;</span><span class="html">li</span> <span class="attr">class</span><span class="kwrd">=&quot;AspNet-Menu-TopLevel-news&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                    <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">=&quot;/WebStyleOnly - Copy/News.aspx&quot;</span><span class="kwrd">&gt;</span>NEWS<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                <span class="kwrd">&lt;</span><span class="html">li</span> <span class="attr">class</span><span class="kwrd">=&quot;AspNet-Menu-TopLevel-about-Selected&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                    <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">=&quot;/WebStyleOnly - Copy/About.aspx&quot;</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">                      ABOUT<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>                <span class="kwrd">&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">            <span class="kwrd">&lt;/</span><span class="html">ul</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre>         <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre class="alt">     <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span></pre>

    <p>&#160;</p>

    <pre> <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>
  </div>

  <p>You can see that the CSS adapter code is not only much smaller, but easier to read and because of the inserted class names, much easier to customize.</p>

  <h2>Conclusions</h2>

  <p>We have not made clear yet how the CSS Friendly Adapters will make the menu&#8217;s work the way we want it to. We have shown css classes created (AspNet-Menu-TopLevel-about-Selected for example) are create by the custom code written by us in the CSS Friendly Adapter Project.&#160; We have however talked about the menu control and showed an example of how the html is actually rendered, and what is rendered based on.&#160; That is, the web.sitemap defines the menu and we have shown that.&#160; In the next article, we will show details of the custom code we have in the CSS Friendly Adapter that solves the problem of how to highlight the menu choices based on what is clicked.</p>

  
</div>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/05/19/codecampwebsiteseries2/feed/</wfw:commentRss>
		<slash:comments>81</slash:comments>
		</item>
		<item>
		<title>Best Practices for Configuring ASP.NET ConnectionStrings and AppSettings in Web.Config</title>
		<link>http://peterkellner.net/2008/02/23/webconfigbestpractice/</link>
		<comments>http://peterkellner.net/2008/02/23/webconfigbestpractice/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 21:25:22 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/02/23/webconfigbestpractice/</guid>
		<description><![CDATA[<p>This article shows a good way to manage connection string and appsettings values in your web.config file.  It shows how to use include files and talks about how to set defaults so moving to production from testing or development can be less painful</p>]]></description>
			<content:encoded><![CDATA[<h2>The Typical Way</h2>  <p>When you first create an asp.net project a file is usually created in your root web directory called web.config.&#160; By default there are two (usually empty) sections in the file.&#160; One for appSettings, and one for connectionStrings.&#160; Below is a default project created with visual studio 2008 and a sample web.config file.</p>  <p><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="webconfig1" src="http://peterkellner.net/misc/webconfig1.jpg" /></p> <span id="more-102"></span>  <p>The thing you would normally do is put stuff in those tags that your application would use.&#160; That is, you would would likely put in a sqlserver connection in the connection tag, then in your appsettings section, you might put something like your smtp mail server location.&#160; Here is what this might look like after you have configured your settings.</p>  <pre class="csharpcode">  <span class="kwrd">&lt;</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">=&quot;UseCache&quot;</span> <span class="attr">value</span><span class="kwrd">=&quot;True&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">=&quot;MapsKey&quot;</span> <span class="attr">value</span><span class="kwrd">=&quot;1234567890-AA&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">=&quot;SMTPServer&quot;</span> <span class="attr">value</span><span class="kwrd">=&quot;smtp.peterkellner.net&quot;</span><span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>

  <span class="kwrd">&lt;</span><span class="html">connectionStrings</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">clear</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;LocalSqlServer&quot;</span>
          <span class="attr">connectionString</span><span class="kwrd">=&quot;Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True&quot;</span>
          <span class="attr">providerName</span><span class="kwrd">=&quot;System.Data.SqlClient&quot;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">connectionStrings</span><span class="kwrd">&gt;</span></pre>

<pre class="csharpcode"><span class="kwrd"></span></pre>

<p>The problem with this approach is that when you deploy your application to a new server, you might want to change your SMTPServer in the AppSettings, and you might want to change your connection string in your ConnectionStrings section.&#160; Usually what happens is that you have to have a separate web.config that you use for production.&#160; The problem is, of course, that you have other things in your web.config that change as you build your application.&#160; You may for example add a new page handler and this means you have to maintain one web.config for production and one for development and you have to modify both of them each time you change something.</p>

<h2>A Better Way</h2>

<p>A solution to this problem (though not the best so read on after this), is to extract appSettings and connectionStrings to a separate file on your server.&#160; Then, you can leave those files on the server and not worry about those changing.&#160; The way this looks is as follows.&#160; You will now have three files to worry about.&#160; web.config (which you had before), and two new files, webAppSettings.config and WebConnectionString.config.&#160; Here are what these three files now look like.</p>

<h3>Web.Config:</h3>

<pre class="csharpcode">  &lt;appSettings file=<span class="str">&quot;webAppSettings.config&quot;</span>&gt;
  &lt;/appSettings&gt;

  &lt;connectionStrings configSource=<span class="str">&quot;WebConnectionString.config&quot;</span>&gt;
  &lt;/connectionStrings&gt;


  &lt;system.web&gt;
        &lt;!-- </pre>

<h3>WebAppSettings.config</h3>

<pre class="csharpcode">&lt;appSettings&gt;
  &lt;add key=<span class="str">&quot;UseCache&quot;</span> <span class="kwrd">value</span>=<span class="str">&quot;True&quot;</span>/&gt;
  &lt;add key=<span class="str">&quot;MapsKey&quot;</span> <span class="kwrd">value</span>=<span class="str">&quot;1234567890-AA&quot;</span>/&gt;
  &lt;add key=<span class="str">&quot;SMTPServer&quot;</span> <span class="kwrd">value</span>=<span class="str">&quot;smtp.peterkellner.net&quot;</span>/&gt;
&lt;/appSettings&gt;</pre>
<style type="text/css">




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<h3>WebConnectionString.config</h3>

<pre class="csharpcode">&lt;connectionStrings&gt;
    &lt;clear/&gt;
    &lt;add name=<span class="str">&quot;LocalSqlServer&quot;</span>
        connectionString=<span class="str">&quot;Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True&quot;</span>
        providerName=<span class="str">&quot;System.Data.SqlClient&quot;</span> /&gt;
&lt;/connectionStrings&gt;</pre>

<p>This actually works, but there is even a best way.</p>

<h2>The Best Way</h2>

<p>I didn&#8217;t realize it until Conrad Cady, a senior developer at our company pointed this out to me.&#160; Basically, it turns out that you can put default values in your web.config AND also have the file= tag in the appSettings tag.&#160; Unfortunately, this only works with AppSetting and the file tag.&#160;&#160; For the connectionStrings, you can not have values inside the connectionString tag if you use the configSource attribute.&#160; That is, you can create a web.config file that looks like the following:</p>

<pre class="csharpcode">&lt;appSettings file=<span class="str">&quot;webAppSettings.config&quot;</span>&gt;
    &lt;add key=<span class="str">&quot;UseCache&quot;</span> <span class="kwrd">value</span>=<span class="str">&quot;True&quot;</span>/&gt;
    &lt;add key=<span class="str">&quot;MapsKey&quot;</span> <span class="kwrd">value</span>=<span class="str">&quot;1234567890-AA&quot;</span>/&gt;
    &lt;add key=<span class="str">&quot;SMTPServer&quot;</span> <span class="kwrd">value</span>=<span class="str">&quot;smtp.peterkellner.net&quot;</span>/&gt;
  &lt;/appSettings&gt;

  &lt;connectionStrings configSource=<span class="str">&quot;WebConnectionString.config&quot;</span>&gt;
  &lt;/connectionStrings&gt;</pre>

<p>What happens is that if you have values in your webAppSettings.config file, they will override what is in your web.config appSettings section. If you have no webAppSettings.config file, then all the values in web.config webAppSettings section are used. </p>

<p>connectionStrings unfortunately does not work the same.&#160; You MUST have a WebConnectionString.config file for this setup and you MUST NOT have any values inside the connectionStrings tag in the web.config file.</p>

<h2>How to Use the &quot;Best Way&quot; in Real Life </h2>

<p>So, the title of this article is &quot;Best Practices&quot;.&#160; So, what is the best practice.&#160; Well, IMHO the best practice is to have your production AppSettings in your web.config file and not have an external file checked into source control (that is, don&#8217;t check in webAppSettings.config).&#160; Only create that file for development servers where you want to override you default (web.config) appSettings keys and attributes.&#160; For connectionStrings, I recommend always using an external file but don&#8217;t actually check it into source control.&#160; Instead, check in a file named WebConnectionString.config.sample and on each environment where you are running a web server, rename that file to WebConnectionString.config so that it will actually be used.&#160; Again, the most important thing is NOT to check into source control a file called WebConnectionString.config or webAppSettings.config.&#160; Both should have sample versions checked in, but not actual ones.&#160; That way, you will avoid overwriting real ones when you check out your source control to a working directory.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/02/23/webconfigbestpractice/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>In C#, When to use String verses string</title>
		<link>http://peterkellner.net/2007/12/29/incsharpwhentousestringversesstring/</link>
		<comments>http://peterkellner.net/2007/12/29/incsharpwhentousestringversesstring/#comments</comments>
		<pubDate>Sat, 29 Dec 2007 18:12:41 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[Best Practices]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/12/29/incsharpwhentousestringversesstring/</guid>
		<description><![CDATA[<p>Just a short ramble on when to use string verses use String in C#.  Basically they compile to the same IL code</p>]]></description>
			<content:encoded><![CDATA[<p>So, technically, String and string mean exactly the same thing in C#.&#160; string, is an alias for String (aka a shorthand) for System.String.&#160; So, when should use which?&#160; It seems that the convention is to use string when you are referring to an object and String when you are referring specifically to the string class.</p> <p>This is basically what is said at this URL:&#160; <a title="http://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String" href="http://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String">http://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String</a></p> <p>Juval Lowy has some coding standards at <a href="http://www.idesign.net">http://www.idesign.net</a> that says basically the same thing.&#160; From the document on IDesign&#8217;s web site the following examples show what is best practices (which I completely agree with).</p> <p><a href="/wp/wp-content/uploads/2007/12/idesign1.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="96" alt="idesign1" src="/wp/wp-content/uploads/2007/12/idesign1-thumb.jpg" width="244" border="0" /></a>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="/wp/wp-content/uploads/2007/12/idesign2.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="144" alt="idesign2" src="/wp/wp-content/uploads/2007/12/idesign2-thumb.jpg" width="244" border="0" /></a></p> <p>That&#8217;s it for now.&#160;</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/12/29/incsharpwhentousestringversesstring/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Media Browser Using Silverlight 1.1 Alpha and Leverage Software&#8217;s REST API</title>
		<link>http://peterkellner.net/2007/09/13/searchlightpart1/</link>
		<comments>http://peterkellner.net/2007/09/13/searchlightpart1/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 01:24:22 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/09/13/searchlightpart1/</guid>
		<description><![CDATA[<br />
<p>Searchlight was born from the desire to show the outstanding ability of
Silverlight to create a compelling web application using existing infrastructure
technology.&#160; The products was developed working with
<a href="http://www.leveragesoftware.com/">Leverage Software, </a>a
San Francisco company dedicated to delivering first class communities for it&#39;s
customer&#39;s, <a href="http://peterkellner.net/about/">Peter Kellner</a> (the Silverlight technology guy), and
<a href="http://udanium.com/about_me.html">Uday Gajendar</a>, the design
specialist.&#160; Our efforts can be viewed by going to the
<a href="http://labs.leveragesoftware.com/silverlight.html">LeverageSoftware Labs Link Here</a>.&#160;
Simply follow the directions on that web page to run the web application.&#160;
In this article, many of the Silverlight features in
Searchlight are discussed.&#160; </p>

<a href="http://searchlight.peterkellner.net/Default.html">
<img alt="click here if you have Silverlight Alpha 1.1 Installed" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image001t.jpg" class="style1"  /></a>
<br />]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>  <p>Searchlight was born from the desire to show the outstanding ability of Silverlight to create a compelling web application using existing infrastructure technology.&#160; The products was developed working with <a href="http://www.leveragesoftware.com/">Leverage Software, </a>a     <br />San Francisco company dedicated to delivering first class communities for it&#8217;s customer&#8217;s, <a href="http://peterkellner.net/about/">Peter Kellner</a> (the Silverlight technology guy), and <a href="http://udanium.com/about_me.html">Uday Gajendar</a>, the design specialist.&#160; Our efforts can be viewed by going to the <a href="http://labs.leveragesoftware.com/silverlight.html">LeverageSoftware Labs Link Here</a>.&#160; Simply follow the directions on that web page to run the web application. In this article, many of the Silverlight features in Searchlight are discussed. </p>  <h2>Background</h2>  <p>Searchlight was built to run with the first Alpha 1.1 version of Silverlight shipped from Microsoft.&#160; Searchlight takes advantage of Leverage Software&#8217;s extensive web service api to provide real time data based on those web feeds.&#160; Currently, Leverage Software&#8217;s&#160; main access to the Dwell Community is an html application that can be found at    <br /><a href="http://dwell.leveragesoftware.com/">http://dwell.leveragesoftware.com/</a>.&#160; Using the Silverlight Alpha 1.1 combined with </p> <span id="more-76"></span>  <p><a href="http://www.microsoft.com/expression/products/overview.aspx?key=blend">Microsoft&#8217;s Expression Blend</a>, a new compelling interface to the Dwell Community was built.&#160; Below is a screen shot of the application running after it has been loaded for the first time.</p>  <p><img src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image001.jpg" width="624" height="408" /></p>  <h2>Dynamic Data Content</h2>  <p>Silverlight supports access to remote data feeds. This allows for interactive applications to be built that rely on external datasources seamlessly.&#160; For example, when the user clicks on the Furniture Menu choice, a query is sent to the Dwell on line community and all members who have pictures tagged with the word furniture are retrieved.</p>  <h2>Responsiveness</h2>  <p>Silverlight runs on the client side which means all user interaction (events) are processed in the browser and do not require a round trip to the server. For example, when the user wants to scroll pictures right to left they would press the green right arrow button and the pictures will scroll.&#160; Notice also the nice halo affect when you mouse over the green scroll button.</p>  <p><img alt="sl2.jpg" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image004.jpg" width="90" height="107" /></p>  <p>Again, because Silverlight is all client side, the speed at which the pictures scroll is determined by how long the user holds down the mouse over the arrow key before releasing. If the user quickly clicks the green arrow button, the pictures move quickly, if they click and hold for a second, then release, the picture will&#160; scroll more slowly.&#160; In addition the little green dots give you immediate feedback of how many pictures are in the entire scrollable region, and where you are in that list.&#160; For example, if you look at the second line of pictures (Wimlarch), you’ll notice that there are    <br />6 green dots with 5 illuminated on the left (as shown below).</p>  <p><img alt="sl3.jpg" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image006.jpg" width="111" height="66" /></p>  <p>This means, you are looking at 5/6ths of the pictures (83 percent), and that you are scrolled all the way to the left. If half the green dots were illuminated, then you would only be looking at half the pictures for that particular person (line). Again, because this is a completely client side programming model (Silverlight), as you scroll, the green dots automatically change and there is no server load and no traffic on the internet (with the exception of the actual    <br />images being downloaded if they have not previously been cached in the browser).</p>  <h2>Layout/Size Management</h2>  <p>It’s important for a real functioning application to be able to manage the information inside it’s borders. The amount of screen area available to the program is different depending on how big the users browser is, as well as how much space the user has allocated to the browser window.</p>  <p>Silverlight exposes a class called the HttpBrowserClass which allows the client software (Silverlight) to react and adjust based on screen size. For example, if the browser size is reduced, the number of rows showing is reduced to the correct number (two in this case) and the pictures showing on each row is reduced to 4. Of course the little green dots adjust also. Here is a screen showing that situation.</p>  <p><img src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image007.jpg" width="624" height="394" /></p>  <p>Notice also that the menu choices are closer together. The point here is that each Silverlight control can change its position dynamically depending on external inputs such as browser size changes.</p>  <h2>Special Effects.</h2>  <p>Silverlight shines when it comes to special effects. Many effects can be achieved, while only a few are demonstrated here. The effects demonstrated here are as follows.</p>  <h3>Picture Growth On Mouse Over </h3>  <p>This means that as you mouse over a picture it slightly grows and when you mouse out it shrinks again.&#160; This is to give you an idea that you can click on it.</p>  <h3>Picture Flipping to the opposite side</h3>  <p>When you click on a picture in the user’s collection, the picture fades in at a higher resolution as below.</p>  <p><img alt="sl5.JPG" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image010.jpg" width="397" height="295" /></p>  <p>If you click on the little orange triangle on the lower right corner of the picture, the picture actually flips over simulating a 3d flip and the information about the picture is displayed on the back side.</p>  <p><img alt="sl6.jpg" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image012.jpg" width="389" height="298" /></p>  <h3>Accents On Mouse Over</h3>  <p>Another Silverlight effect is what happens when you mouse over one of the green left or right arrow buttons.&#160; Small expanding circles grow out of the button to indicate that this is something that can be pressed.</p>  <h3>Links to External Web Sites</h3>  <p>Silverlight supports many features of standard web browsers including the ability to link to external web sites. If you bring up the Credits screen by pressing the “Credits” button in the upper right corner, you will see the screen below.</p>  <p><img alt="sl7.jpg" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image014.jpg" width="624" height="458" /></p>  <p>Notice that under each of our names, there is a “View Website” button.&#160; When this button is pressed, a new browser window is opened containing the information about one of us.&#160; You can also get to more information about one of the members by clicking on their picture on the far left of the picture row.</p>  <h3>Asynchronous Processing</h3>  <p>Silverlight allows multiple things to be done at the same time. For example, when the program first loads, an initial web feed from the dwell community is retrieved. This can take several seconds so instead of nothing happening, a small image is displayed with dynamic content.</p>  <p><img alt="sl8.jpg" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image016.jpg" width="134" height="170" /></p>  <p>The little dial circles showing time passing. When the web download is complete, Silverlight has the built in capability to notify the running program that the work is complete so it can continue and bring all the controls and pictures to life.</p>  <h3>Multiple Ways to See Similar Data</h3>  <p>Silverlight has a complete custom programming model that allows the developer to show the data in lots of different ways. On the opening screen, if the user presses the “View Gallery” button on any of the picture rows, they will get a screen that looks like what is below.</p>  <p><img alt="sl10.jpg" src="http://peterkellner.net/wp/Images/SearchLightPart1/clip_image018.jpg" width="624" height="452" /></p>  <p>Notice that as the picture is scrolled through the artists collection, the title and information about the picture is displayed. Again, this all happens with no server interaction or traffic.</p>  <h2>Conclusions</h2>  <p>Silverlight is indeed a compelling technology to build applications that can be run anywhere on the internet.&#160; Searchlight demonstrates just a small number of Silverlight&#8217;s great features.&#160; Understanding that there are always lots of ways to deliver the same result, Silverlight does give a way to deliver very rich content using the Microsoft development stack.&#160; In this case, that includes Visual Studio, Microsoft Expressions Blend and of course the    <br />.Net Programming language c#.&#160; Many of the features of Silverlight .net alpha 1.1 are not yet available, so we anticipate when the final production release comes, we will be able to deliver even more functionality, even more efficiently than we can do it now.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/09/13/searchlightpart1/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Code Camp Presentation Coming 10/27-28/2008 on Silverlight, Los Altos, California</title>
		<link>http://peterkellner.net/2007/09/12/codecampsv07presentation/</link>
		<comments>http://peterkellner.net/2007/09/12/codecampsv07presentation/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 05:06:19 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/09/12/codecampsv07presentation/</guid>
		<description><![CDATA[I'll be presenting a session at the upcoming Code Camp in Silicon Valley's Foothill College on October 27th-28th.  Details can be found at <a href="http://www.siliconvalley-codecamp.com/Sessions.aspx?ForceSortBySessionTime=true&#38;id=125">
http://www.siliconvalley-codecamp.com/Sessions.aspx?ForceSortBySessionTime=true&#38;id=125</a>.
<br />
<a href="http://www.SiliconValley-Codecamp.com/Home.aspx"  ><img src="http://www.siliconvalley-codecamp.com/DisplayAd.ashx?ImageType=2" alt="CodeCamp at FootHill College.  Click Here for Details and Registration" longdesc="" /></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m presenting a session on Silverlight 1.1 at Silicon Valley Code Camp October 27-28, 2007. this event will be held at Foothill College. If you can make it, please register here:   <br /><a href="http://www.siliconvalley-codecamp.com/AttendeeRegistration.aspx">     <br />http://www.siliconvalley-codecamp.com/AttendeeRegistration.aspx</a></p>  <p>So, you might be wondering, what is a code camp, and what does it cost? Well, it&#8217;s completely free and completely staffed by volunteers. It&#8217;s a place you can share your passion for technology with others like yourself, it&#8217;s a place you can give a presentation on your favorite topic to a receptive audience, as well as go to sessions by others who want to share the knowledge. Typically, there are sessions on all kinds of technologies from Microsoft&#8217;s latest stuff to Java,   <br />Ruby, Python, JavaScript, and even more obscure technologies. It&#8217;s basically formatted like a 1 day PDC/Teched/JavaOne style event where sessions are pre arranged and you just choose what interests you. Session sign up closes a week before the event so you know what you&#8217;ll be in for ahead of time and you can plan.</p> <span id="more-75"></span>  <p>At any rate, my session is at this URL:</p>  <p><a href="http://www.siliconvalley-codecamp.com/Sessions.aspx?ForceSortBySessionTime=true&amp;id=125">     <br />http://www.siliconvalley-codecamp.com/Sessions.aspx?ForceSortBySessionTime=true&amp;id=125</a></p>  <p>The more people come, the more fun it will be.</p>  <p>See you at Camp!</p>  <p><a href="http://www.SiliconValley-Codecamp.com/Home.aspx"><img alt="CodeCamp at FootHill College.  Click Here for Details and Registration" src="http://www.siliconvalley-codecamp.com/DisplayAd.ashx?ImageType=4" longdesc="" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/09/12/codecampsv07presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silicon Valley Code Camp Integrates the DevExpress Cloud Control for Sessions</title>
		<link>http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/</link>
		<comments>http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 19:11:58 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Atlas/AJAX]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/</guid>
		<description><![CDATA[Using the DevExpress CloudControl in the ASP.NET 2.0 Silicon Valley Code Camp's web site was easy.  In this short post, you'll hear about the details and see some code.]]></description>
			<content:encoded><![CDATA[<p>Recently, is seems that many web sites and blogs are starting to use a navigation technique where you have multiple hyperlinks grouped in a box, with size, color, or brightness giving some meaning.&#160; I like this very much and have been on the lookout for a while for a control to do this in ASP.NET.&#160; Turns out, DevExpress has one!&#160; It&#8217;s called the CloudControl and you can read more about it at the following URL.</p> <span id="more-74"></span>  <p>&#160;<a href="http://www.devexpress.com/Products/NET/WebForms/ASPxCloudControl/Index.xml">http://www.devexpress.com/Products/NET/WebForms/ASPxCloudControl/Index.xml</a></p>  <p>So, now, where to use it?&#160; Code Camp of course!&#160; Now, if you browse to the Sessions listing, you&#8217;ll see the DevExpress Cloud Control in use.</p>  <p><img alt="Silicon Valley Code Camp Cloud Control" src="http://peterkellner.net/wp/Images/misc/cloudcontrol.jpg" /></p>  <p>You can see this control in action at our web site here:&#160; <br /><a href="http://www.siliconvalley-codecamp.com/Sessions.aspx">     <br />http://www.siliconvalley-codecamp.com/Sessions.aspx</a></p>  <p>My experience with using this control was great!&#160; Easy to setup.&#160; Below is all the code I needed on my asp page to make it happen.</p>  <p>&#160;<!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1 &lt;\cf3 dxcc\cf1 :\cf3 ASPxCloudControl\cf0  \cf5 ID\cf1 =&#8221;ASPxCloudControl1&#8243;\cf0  \cf5 runat\cf1 =&#8221;server&#8221;\cf0  \par ??           \cf5 DataSourceID\cf1 =&#8221;ObjectDataSourceCloudControl&#8221;\cf0  \cf5 ShowValues\cf1 =&#8221;True&#8221;\cf0  \par ??           \cf5 HorizontalAlign\cf1 =&#8221;NotSet&#8221;\cf0  \cf5 TextField\cf1 =&#8221;TagName&#8221;\cf0  \cf5 ValueField\cf1 =&#8221;TagCount&#8221;\cf0  \par ??           \cf5 NavigateUrlField\cf1 =&#8221;TagId&#8221;\cf0  \par ??           \cf5 NavigateUrlFormatString\cf1 =&#8221;Sessions.aspx?sortby=title&amp;by=category&amp;tag=\{0\}&#8221;\cf0  \par ??           \cf5 ToolTip\cf1 =&#8221;CloudControl Provided From DevExpress&#8221;&gt;\par ??\cf0                 \cf1 &lt;\cf3 RankProperties\cf1 &gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                 \cf1 &lt;/\cf3 RankProperties\cf1 &gt;\par ??\cf0         \cf1 &lt;/\cf3 dxcc\cf1 :\cf3 ASPxCloudControl\cf1 &gt;\par ??\cf0         \cf1 &lt;\cf3 asp\cf1 :\cf3 ObjectDataSource\cf0  \cf5 ID\cf1 =&#8221;ObjectDataSourceCloudControl&#8221;\cf0  \cf5 runat\cf1 =&#8221;server&#8221;\cf0  \par ??            \cf5 SelectMethod\cf1 =&#8221;GetAllTags&#8221;\cf0  \cf5 TypeName\cf1 =&#8221;CodeCampSV.SessionTagsODS&#8221;&gt;\par ??\cf0         \cf1 &lt;/\cf3 asp\cf1 :\cf3 ObjectDataSource\cf1 &gt;}<br />
&#8211;></p>  <div style="font-family: courier new; background: white; color: black; font-size: 10pt">   <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 52</span>&#160;<span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">ASPxCloudControl</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ASPxCloudControl1&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 53</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">DataSourceID</span><span style="color: blue">=&quot;ObjectDataSourceCloudControl&quot;</span> <span style="color: red">ShowValues</span><span style="color: blue">=&quot;True&quot;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 54</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">HorizontalAlign</span><span style="color: blue">=&quot;NotSet&quot;</span> <span style="color: red">TextField</span><span style="color: blue">=&quot;TagName&quot;</span> <span style="color: red">ValueField</span><span style="color: blue">=&quot;TagCount&quot;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 55</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">NavigateUrlField</span><span style="color: blue">=&quot;TagId&quot;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 56</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">NavigateUrlFormatString</span><span style="color: blue">=&quot;Sessions.aspx?sortby=title&amp;by=category&amp;tag={0}&quot;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 57</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">ToolTip</span><span style="color: blue">=&quot;CloudControl Provided From DevExpress&quot;&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 58</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">RankProperties</span><span style="color: blue">&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 59</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 60</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 61</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 62</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 63</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 64</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 65</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 66</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: #a31515">RankProperties</span><span style="color: blue">&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 67</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">ASPxCloudControl</span><span style="color: blue">&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 68</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ObjectDataSource</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ObjectDataSourceCloudControl&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 69</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">SelectMethod</span><span style="color: blue">=&quot;GetAllTags&quot;</span> <span style="color: red">TypeName</span><span style="color: blue">=&quot;CodeCampSV.SessionTagsODS&quot;&gt;</span></p>    <p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 70</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ObjectDataSource</span><span style="color: blue">&gt;</span></p> </div>  <p style="margin: 0px">&#160;</p>  <p style="margin: 0px">This is my first trip into the Developer Express toolbox and so far, I&#8217;m very impressed!</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Always Set Stop On Exception While Doing Debugging in Visual Studio 2005 or 2008</title>
		<link>http://peterkellner.net/2007/08/10/stoponexceptionvs/</link>
		<comments>http://peterkellner.net/2007/08/10/stoponexceptionvs/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 16:05:12 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/08/10/stoponexceptionvs/</guid>
		<description><![CDATA[<p>This article discusses a best practices method for automatically having the debugger stop on unhandled exceptions in visual studio 2005 or 2008</p>]]></description>
			<content:encoded><![CDATA[<p>One of the tricks I&#8217;ve learned over time is to always set visual studio to stop on a thrown exception.&#160; Normally, during running of a .net application, unhandled exceptions are simply processed and absorbed quietly.&#160; For the most part, this is good because you do not want your users to see error messages all the time, and likely what is being thrown is not interesting anyhow.&#160; It is however bad because throwing exceptions is very time consuming for the application as well as it may actually be something important.</p>  <p>To keep this from happening, my &quot;best practice&quot; is to go into the menu choice Debug/Exceptions as follows:</p>  <p><img alt="Debug Excetpion Menu Choice" src="http://peterkellner.net/wp/Images/misc/vsexceptions1.jpg" /></p> <span id="more-71"></span>  <p>Then, you will get the following dialog.&#160; Make sure to check everything as show below:</p>  <p><img alt="Debug Excetpion Menu Choice" src="http://peterkellner.net/wp/Images/misc/vsexceptions.jpg" /></p>  <p>Then, when you hit an exception while debugging, the debugger will stop on the offending line so you can figure out if you should be surrounding this with a try/catch, or whether it&#8217;s just an oversight you need to fix.</p>  <p>Good luck with this!&#160; It&#8217;s helped me a huge amount in finding bugs I would have likely found later and much more painfully.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/08/10/stoponexceptionvs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 4/13 queries in 0.002 seconds using disk

Served from: peterkellner.net @ 2012-02-04 06:08:35 -->
