<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.stevesmithblog.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0"><channel><title>Steve Smith's Blog</title><link>http://stevesmithblog.com/</link><description>Musings on Software and the Developer Community</description><generator>Graffiti CMS 1.2 (build 1.2.0.2308)</generator><lastBuildDate>Mon, 26 Jul 2010 21:13:00 GMT</lastBuildDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.stevesmithblog.com/StevenSmith" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="stevensmith" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">StevenSmith</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Books</title><link>http://stevesmithblog.com/blog/books/</link><pubDate>Mon, 26 Jul 2010 21:13:00 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/books/</guid><dc:creator>ssmith</dc:creator><slash:comments>3</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;&lt;a href="http://codinggeekette.com/post/Books-Check-Em-Out!.aspx" rel="nofollow"&gt;Sadukie tagged me with her books post&lt;/a&gt; a couple of weeks ago and I’ve been meaning to respond with a post of my own.&amp;#160; I have a post I update periodically that includes some of my most &lt;a href="http://stevesmithblog.com/blog/favorite-developer-books/"&gt;recommended developer books&lt;/a&gt; (where I’ve been meaning to add &lt;a href="http://www.amazon.com/gp/product/0131857258?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0131857258"&gt;Agile Principles, Patterns, and Practices in C# by Robert and Micah Martin&lt;/a&gt;) – if you’re looking for ways to improve yourself as a software developer I would start there.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Currently Reading&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Right now I’m reading &lt;a href="http://www.amazon.com/gp/product/0345391055?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0345391055"&gt;Disclosure&lt;/a&gt;, by Michael Crichton.&amp;#160; I’m a fan of his stuff, and in the last year I also read &lt;a href="http://www.amazon.com/gp/product/B0017TZKRG?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=B0017TZKRG"&gt;Next&lt;/a&gt;, &lt;a href="http://www.amazon.com/gp/product/0061782661?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0061782661"&gt;State of Fear&lt;/a&gt;, and &lt;a href="http://www.amazon.com/gp/product/0451210638?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0451210638"&gt;A Case of Need&lt;/a&gt;.&amp;#160; I’ve also been reading a lot of James Rollins novels (which &lt;a href="http://greatandsmallblog.com/"&gt;Michelle&lt;/a&gt; got me started on), which are good light entertaining reads.&amp;#160; I’ve read &lt;a href="http://www.amazon.com/gp/product/0061965820?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0061965820"&gt;Deep Fathom&lt;/a&gt; and &lt;a href="http://www.amazon.com/gp/product/0060580674?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0060580674"&gt;Sandstorm&lt;/a&gt; and &lt;a href="http://www.amazon.com/gp/product/0061965839?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0061965839"&gt;Amazonia&lt;/a&gt;, and I think my next one is &lt;a href="http://www.amazon.com/gp/product/0060765240?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0060765240"&gt;Map of Bones&lt;/a&gt;, which I’ve not yet started.&amp;#160; Deep Fathom is a good one to start with if you’re so inclined.&amp;#160; The &lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;amp;location=http%3A%2F%2Fwww.amazon.com%2Fs%3Fie%3DUTF8%26x%3D0%26ref_%3Dnb%5Fsb%5Fnoss%26fsc%3D-1%26ih%3D12%5F5%5F2%5F0%5F0%5F0%5F0%5F0%5F0%5F1.39%5F74%26y%3D0%26field-keywords%3Dpercy%2520jackson%26url%3Dsearch-alias%253Dus-stripbooks-tree&amp;amp;tag=aspalliancecom&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=39095"&gt;Percy Jackson books&lt;/a&gt;, which I read shortly after my then-7-year-old daughter read, were also fun and entertaining.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Digital Reader&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;My wife got me a Nook for Christmas this past year, and I took it on several trips and loaded it with a few books from the library and PDFs of things I wanted to read later.&amp;#160; It worked pretty well at first, but I have to say I’m not very happy with it at the moment.&amp;#160; It keeps getting into a state where I can’t turn it on or interact with it.&amp;#160; I won’t bore you with the details of all the various rituals I’ve gone through in terms of charging, connecting to AC vs. PC for power, resetting, etc. but suffice to say it’s been rather frustrating (even moreso than trying to get it out of its original packaging, for which there are &lt;a href="http://nookboards.com/2010/01/07/nook-unboxing/" rel="nofollow"&gt;videos to show you how to do it&lt;/a&gt;).&amp;#160; In short, I think I would rather try a Kindle, or maybe even an iPad, in lieu of this device.&amp;#160; The one thing that it has that’s cool, which I’m not sure the other devices support, is grabbing digital books from the local library.&amp;#160; But of course when you can’t get the thing to turn on, the allure of such things fades.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Recommendations&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;One book I really enjoyed reading last year is &lt;a href="http://www.amazon.com/gp/product/0061673730?ie=UTF8&amp;amp;tag=aspalliancecom&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0061673730"&gt;Zen and the Art of Motorcycle Maintenance&lt;/a&gt;.&amp;#160; I’ve been meaning to blog about the book and its relationship to Software Craftsmanship (which, by the way, there’s &lt;a href="http://hudsonsc.com/"&gt;a group that meets in Hudson Ohio monthly to improve themselves&lt;/a&gt; in this regard), and hopefully I’ll get that done soon.&amp;#160; However, whether you’re a software developer or not, this is certainly an interesting book to read.&amp;#160; There are some great lessons about &lt;em&gt;quality&lt;/em&gt; that I think are worthwhile for any reader.&lt;/p&gt;  &lt;p&gt;Also, though they’re not books, I highly recommend the web comics &lt;a href="http://xkcd.com/"&gt;XKCD&lt;/a&gt; and &lt;a href="http://calamitiesofnature.com/"&gt;Calamities of Nature&lt;/a&gt; for geeks.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Tag!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;So what are you folks reading these days?&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://brendan.enrick.com/" rel="nofollow"&gt;Brendan Enrick&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://scottdepouw.com/" rel="nofollow"&gt;Scott Depouw&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.hanselman.com/blog/" rel="nofollow"&gt;Scott Hanselman&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://scottw.com/" rel="nofollow"&gt;Scott Watermasysk&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/gduthie/" rel="nofollow"&gt;Andrew Duthie&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_d3hPLLREvhN3rxFePp4eWjoVeA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_d3hPLLREvhN3rxFePp4eWjoVeA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_d3hPLLREvhN3rxFePp4eWjoVeA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_d3hPLLREvhN3rxFePp4eWjoVeA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=SEg0_KWZNhY:fqf9QXpEy2w:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=SEg0_KWZNhY:fqf9QXpEy2w:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=SEg0_KWZNhY:fqf9QXpEy2w:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=SEg0_KWZNhY:fqf9QXpEy2w:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=SEg0_KWZNhY:fqf9QXpEy2w:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=SEg0_KWZNhY:fqf9QXpEy2w:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/SEg0_KWZNhY" height="1" width="1"/&gt;</description></item><item><title>Working with Application Pool Identities</title><link>http://stevesmithblog.com/blog/working-with-application-pool-identities/</link><pubDate>Fri, 09 Jul 2010 13:16:00 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/working-with-application-pool-identities/</guid><dc:creator>ssmith</dc:creator><slash:comments>0</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;There a new feature of IIS called Application Pool Identities that was apparently introduced with SP2 of Windows Server 2008.&amp;#160; There’s a nice overview of &lt;a href="http://learn.iis.net/page.aspx/624/application-pool-identities/" rel="nofollow"&gt;Application Pool Identities here&lt;/a&gt;, which is the basis for this post, which is just my notes on the feature.&lt;/p&gt;  &lt;p&gt;If you’re setting up new web sites and application pools in IIS on Windows Server 2008, it’s likely they’ll default to ApplicationPoolIdentity, like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Application Pools" border="0" alt="Application Pools" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/WorkingwithApplicationPoolIdentities_F2DF/image_3.png" width="485" height="216" /&gt; &lt;/p&gt;  &lt;p&gt;This is all well and good, and for the most part you don’t need to care about how this works behind the scenes or why it’s different than the other bazillion different esoteric accounts you’ve had to know about over the last 10 years when setting up IIS for ASP.NET (IUSR_MACHINENAME, NETWORKSERVICE, IUSR, etc.).&amp;#160; The most recent installment in IIS user best practices, before ApplicationPoolIdentity, was NETWORKSERVICE:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;NETWORKSERVICE is a built-in Windows identity. It doesn't require a password and has only user privileges; that is, it is relatively low-privileged.&amp;#160; However, a problem arose over time as more and more Windows system services started to run as NETWORKSERVICE. This is because services running as NETWORKSERVICE can tamper with other services that run under the same identity. Because IIS worker processes run third-party code by default (Classic ASP, ASP.NET, PHP code), it was time to isolate IIS worker processes from other Windows system services and run IIS worker processes under unique identities.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Got that?&amp;#160; The NETWORKSERVICE account was low-privileged, so it was a best practice to use it.&amp;#160; But unfortunately, since so many apps followed this practice, it became likely that NETWORKSERVICE would have too much access to a variety of applications/processes, so something new had to be used.&lt;/p&gt;  &lt;p&gt;Enter Application Pool Identities.&amp;#160; On IIS7.5 on Windows Server 2008 R2, your application pools will run with their own individual identity, each of which is actually a &lt;a href="http://technet.microsoft.com/en-us/library/dd548356.aspx" rel="nofollow"&gt;virtual account&lt;/a&gt; created with the same name as your application pool.&amp;#160; You may see these accounts in the ACLs for the files in your web site, and you’ll need to know how to reference them yourself if you want to configure security settings for your site correctly (e.g. to allow users to upload files to your web application).&amp;#160; &lt;strong&gt;They are not actually users or accounts, so they will not show up as a user in the Windows User Management Console.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For example, if you look at the Security settings for a particular filesystem object in your web application, you might see something like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Security Settings" border="0" alt="Security Settings" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/WorkingwithApplicationPoolIdentities_F2DF/image_6.png" width="356" height="448" /&gt; &lt;/p&gt;  &lt;p&gt;Note, though, that if you go looking for these users on the server, you won’t find them.&amp;#160; If you choose to change permissions by clicking Edit, then Add, then change the location to your server (if it defaults to a domain), then Advanced, and finally Find Now (yes, that’s a lot of buttons), you WON’T SEE THESE ACCOUNTS:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Select Users or Groups" border="0" alt="Select Users or Groups" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/WorkingwithApplicationPoolIdentities_F2DF/image_9.png" width="368" height="416" /&gt; &lt;/p&gt;  &lt;p&gt;So where are they and how do you add them?&lt;/p&gt;  &lt;p&gt;You have to know the secret, which is to prefix Application Pool Identities with &lt;/p&gt;  &lt;p&gt;IIS AppPool\&lt;/p&gt;  &lt;p&gt;Thus to grant rights to the DefaultAppPool you need to use &lt;/p&gt;  &lt;p&gt;IIS AppPool\DefaultAppPool.&amp;#160; &lt;/p&gt;  &lt;p&gt;If your application pool is named mywebsite.com, then your identity would be&lt;/p&gt;  &lt;p&gt;IIS AppPool\mywebsite.com&lt;/p&gt;  &lt;p&gt;When they appear in your ACL list, the IIS AppPool won’t be listed.&amp;#160; This is to ensure greater confusion on your part, because you don’t have enough things to try and remember as a web developer and/or server administrator.&amp;#160; If you type in the correct value and then click Check Names, it will remove the IIS AppPool\ prefix and underline the account name for you, like so:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Before Check Names" border="0" alt="Before Check Names" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/WorkingwithApplicationPoolIdentities_F2DF/image_15.png" width="454" height="235" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="After Check Names" border="0" alt="After Check Names" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/WorkingwithApplicationPoolIdentities_F2DF/image_14.png" width="456" height="244" /&gt; &lt;/p&gt;  &lt;p&gt;Hope this helps! For more info I suggest reading this &lt;a href="http://learn.iis.net/page.aspx/624/application-pool-identities/" rel="nofollow"&gt;article on Application Pool Identities&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Also, don’t forget you can follow me via &lt;a href="http://twitter.com/ardalis"&gt;twitter&lt;/a&gt;, &lt;a href="http://feedburner.google.com/fb/a/mailverify?uri=StevenSmith"&gt;email&lt;/a&gt;, or &lt;a href="http://feeds.feedburner.com/StevenSmith"&gt;RSS&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ey_q2VkWPCvUZSMF6iLGM9bqRXE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ey_q2VkWPCvUZSMF6iLGM9bqRXE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ey_q2VkWPCvUZSMF6iLGM9bqRXE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ey_q2VkWPCvUZSMF6iLGM9bqRXE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=m_CAzJjROwM:Mlb1ZI_4YkY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=m_CAzJjROwM:Mlb1ZI_4YkY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=m_CAzJjROwM:Mlb1ZI_4YkY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=m_CAzJjROwM:Mlb1ZI_4YkY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=m_CAzJjROwM:Mlb1ZI_4YkY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=m_CAzJjROwM:Mlb1ZI_4YkY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/m_CAzJjROwM" height="1" width="1"/&gt;</description></item><item><title>Software Engineering 101 in Cleveland</title><link>http://stevesmithblog.com/blog/software-engineering-101-in-cleveland/</link><pubDate>Wed, 07 Jul 2010 19:34:39 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/software-engineering-101-in-cleveland/</guid><dc:creator>ssmith</dc:creator><slash:comments>0</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;Next week I’ll be one of several speakers at a free one-day event being held at the Microsoft office in Independence, Ohio.&amp;#160; The event is designed for Microsoft developers who are seeking to improve their skills in software engineering, including object-oriented design, design patterns, and automated testing.&amp;#160; The event is being hosted by Microsoft and organized by the &lt;a href="http://HudsonSC.com/"&gt;Hudson Software Craftsmanship group&lt;/a&gt; and &lt;a href="http://NimblePros.com/"&gt;NimblePros consulting services&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Initially there were 50 slots available – I think there are about 15-20 left as of today.&amp;#160; The event is scheduled for 16 July 2010 from 830am to 4pm, so if you can get approval to come for some free hands-on training, sign up fast before it’s sold out.&lt;/p&gt;  &lt;p&gt;You can register for the event and view the agenda &lt;a href="http://nimblepros.com/news-and-events/software-engineering-101---cleveland.aspx"&gt;here&lt;/a&gt;.&amp;#160; If you’re planning on attending the Cleveland Give Camp, there will be a number of folks going to both, and the SWE101 event should wrap up in plenty of time to make it to the GiveCamp.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ACv8VDSrZkNrcgcLrz5B_jJ9w6I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ACv8VDSrZkNrcgcLrz5B_jJ9w6I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ACv8VDSrZkNrcgcLrz5B_jJ9w6I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ACv8VDSrZkNrcgcLrz5B_jJ9w6I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=3Dd1vPo8Lig:vK7QzlNfF64:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=3Dd1vPo8Lig:vK7QzlNfF64:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=3Dd1vPo8Lig:vK7QzlNfF64:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=3Dd1vPo8Lig:vK7QzlNfF64:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=3Dd1vPo8Lig:vK7QzlNfF64:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=3Dd1vPo8Lig:vK7QzlNfF64:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/3Dd1vPo8Lig" height="1" width="1"/&gt;</description></item><item><title>Set Up Build Agents By Project in TeamCity</title><link>http://stevesmithblog.com/blog/set-up-build-agents-by-project-in-teamcity/</link><pubDate>Wed, 07 Jul 2010 15:22:00 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/set-up-build-agents-by-project-in-teamcity/</guid><dc:creator>ssmith</dc:creator><slash:comments>0</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;We’re using TeamCity to manage our continous integration builds for CodeProject.com and LakeQuincy.com.&amp;#160; Before TeamCity, I was using CruiseControl.net, and TeamCity is much easier to get working (and requires far less XML manipulation).&amp;#160; I do miss CCTray, which I found to be much nicer than the TeamCity tray notifier (which if you click on it never shows anything immediately – it has to go and get it which imposes a delay – it also doesn’t do sounds like CCTray does – but I digress).&lt;/p&gt;  &lt;p&gt;Let’s say you have several large projects and you want them to run on the same instance of TeamCity.&amp;#160; Let’s further assume that some of these build configurations do a lot of stuff, and thus might take 10 minutes or more to run, while others are for relatively small projects or web sites that might take 30 seconds or less to run.&amp;#160; If you were to check in one of these small sites, hoping to quickly see the build server turn green, you would be rather frustrated if your timing were poor and you had to wait 10 minutes for a larger project that was unrelated to your project to finish its build.&amp;#160; Beyond the frustration, this causes a very real and negative impact on your productivity.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;1) Create another build server.&amp;#160; The TeamCity tray notifier can now &lt;a href="http://confluence.jetbrains.net/display/TCD5/How+To...#HowTo...-InstallMultipleAgentsontheSameMachine" rel="nofollow"&gt;talk to more than one instance of TeamCity&lt;/a&gt; (though I haven’t tried it myself), so this would be one option if you have the hardware available.&lt;/p&gt;  &lt;p&gt;2) Add another build agent.&amp;#160; The agent does the real work of building your projects, and you can install multiple agents based on your license of TeamCity.&amp;#160; These can live on the same server or on different machines.&amp;#160; &lt;strong&gt;This is the approach I’m demonstrating here&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;3) Live with it.&amp;#160; This is the default approach, of course, and is listed only to make you think this is an exhaustive list of options.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Installing an Agent&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Assuming you already have TeamCity set up and running, installing a new agent is pretty simple.&amp;#160; If you click on Administration, you should see a link just below the search bar to Install Build Agents, like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/SetUpBuildAgentsByProjectinTeamCity_F468/image_3.png" width="455" height="344" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Before you do anything, you should read about configuring this new agent!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Specifically, there are some notes on things you need to know about installing multiple agents on the same machine.&amp;#160; &lt;a href="http://confluence.jetbrains.net/display/TCD5/How+To...#HowTo...-InstallMultipleAgentsontheSameMachine"&gt;Read them here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Assuming you’re on a windows machine, you can go ahead and use the MS Windows Installer.&lt;/p&gt;  &lt;p&gt;Make sure you edit the \launcher\conf\wrapper.conf file and change the following properties so they are unique among your agents:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;wrapper.console.title&lt;/li&gt;    &lt;li&gt;wrapper.ntservice.name&lt;/li&gt;    &lt;li&gt;wrapper.ntservice.displayname&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you don’t modify these, then what will happen is your new agent will give your old agent the boot, as it were, and you’ll still have only one agent running on the machine as a service, but it will be pointing at the new folders you told it to use for the second agent.&lt;/p&gt;  &lt;p&gt;Also, if you find yourself faced with an error when trying to create or delete a service using the scripts for doing so that are included in the agent folders, try closing the services.msc dialog.&amp;#160; I found that it was preventing me from deleting some services (that I was trying to then recreate).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Specify Build Agents for Projects&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Having two (or more) build agents is great, but now all that’s going to happen is every project will just get picked up by whichever agent happens to be free.&amp;#160; And each agent will need to have a working copy of every project, which multiplies the disk space needed and the traffic with the VCS server.&amp;#160; If you have large projects, these can be real concerns.&amp;#160; So how do you specify that a particular agent should be associated only with a certain set of projects?&amp;#160; Through the use of &lt;a href="http://www.thinkplexx.com/learn/howto/build-chain/ci/set-environment-and-properties-for-teamcity-build-agent-reconnect-use-them-in-projects"&gt;agent environment variables, as discussed here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Specifically, in the &lt;strong&gt;buildAgent.properties&lt;/strong&gt; file (in the &lt;strong&gt;/conf&lt;/strong&gt; folder), you can add your own user defined values.&amp;#160; Here’s an example of the configuration file for the Lake Quincy build agent:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;name=LQ Build Agent&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;ownPort=9091&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;serverUrl=http\:&lt;span style="color: #008000"&gt;//localhost\:90&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;workDir=D\:\\TeamCity\\LQBuildAgent\\Work&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;tempDir=D\:\\TeamCity\\LQBuildAgent\\Temp&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;#User defined properties&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;env.lakequincy=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;env.TEAMCITY_JRE=C\:\\Program Files\\Java\\jre6&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Notice the env.lakequincy value.&amp;#160; What it’s set to is actually not important, as you’ll see in a moment.&amp;#160; You’ll want to add such an environment variable to each agent, designating which kinds of projects it should work on.&lt;/p&gt;

&lt;p&gt;Next, in TeamCity’s web interface, go to each of your projects and update their Agent Requirements (configuration step 7).&amp;#160; In my case, I’m going to &lt;strong&gt;Add requirement for a variable &lt;/strong&gt;and say that the project’s agent must have an environment variable called env.lakequincy and that it must exist.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/SetUpBuildAgentsByProjectinTeamCity_F468/image_6.png" width="489" height="128" /&gt; &lt;/p&gt;

&lt;p&gt;Once this is done, you should see the correct build agents listed as Compatible, and all others listed as Incompatible, with the reason listed for the incompatibility:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/SetUpBuildAgentsByProjectinTeamCity_F468/image_9.png" width="489" height="176" /&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s pretty easy to get continuous integration working with TeamCity, and very easy to add additional agents to a single server (using unique paths and service names).&amp;#160; If you want to dedicate some agents to certain projects or tasks, you can easily do so by using environment variables as shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oSfyXV8rhnXbmN9nChtbnS6lErk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oSfyXV8rhnXbmN9nChtbnS6lErk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oSfyXV8rhnXbmN9nChtbnS6lErk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oSfyXV8rhnXbmN9nChtbnS6lErk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=gaiyWyrNlRg:RgbqjKYGiTM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=gaiyWyrNlRg:RgbqjKYGiTM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=gaiyWyrNlRg:RgbqjKYGiTM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=gaiyWyrNlRg:RgbqjKYGiTM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=gaiyWyrNlRg:RgbqjKYGiTM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=gaiyWyrNlRg:RgbqjKYGiTM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/gaiyWyrNlRg" height="1" width="1"/&gt;</description></item><item><title>How Can I Determine The Current Controller or Action in an Html Helper</title><link>http://stevesmithblog.com/blog/how-can-i-determine-the-current-controller-or-action-in-an-html-helper/</link><pubDate>Fri, 02 Jul 2010 18:42:04 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/how-can-i-determine-the-current-controller-or-action-in-an-html-helper/</guid><dc:creator>ssmith</dc:creator><slash:comments>3</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;If you’re writing an HTML Helper for ASP.NET MVC you may want to do something different based on whether the page that is to be rendered was arrived at via a particular controller or controller action.&amp;#160; I found the following code which does just this in one of the ASP.NET MVC Themes available from the &lt;a href="http://www.asp.net"&gt;www.asp.net&lt;/a&gt; web site (the Dark theme, I believe it’s called).&lt;/p&gt;  &lt;p&gt;Note that I’ve already modified this code to &lt;a href="http://stevesmithblog.com/blog/default-encoding-of-strings-in-asp-net-mvc-2/"&gt;work with the new ASP.NET 4 string encoding and the MvcHtmlString type&lt;/a&gt;, as I wrote about previously.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; MvcHtmlString LoginLink(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; HtmlHelper helper)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentControllerName = &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)helper.ViewContext.RouteData.Values[&lt;span style="color: #006080"&gt;&amp;quot;controller&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentActionName = &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)helper.ViewContext.RouteData.Values[&lt;span style="color: #006080"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isAuthenticated = &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      helper.ViewContext.HttpContext.Request.IsAuthenticated;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #008000"&gt;// more stuff here&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;As you can see, the HtmlHelper has a ViewContext property, which allows you to access RouteData and ultimately from there determine the controller and/or action that was used for this request.&amp;#160; Incidentally, you can also use the ViewContext to get to HttpContext and determine whether the request is authenticated as well.&lt;/p&gt;

&lt;p&gt;And that’s it!&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can &lt;/em&gt;&lt;a href="http://twitter.com/ardalis"&gt;&lt;em&gt;follow me on twitter here&lt;/em&gt;&lt;/a&gt;&lt;em&gt; or &lt;/em&gt;&lt;a href="http://feeds.feedburner.com/StevenSmith"&gt;&lt;em&gt;subscribe to my blog here&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5oENnJhdNaja9OyM5LAKVSCrhXE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5oENnJhdNaja9OyM5LAKVSCrhXE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5oENnJhdNaja9OyM5LAKVSCrhXE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5oENnJhdNaja9OyM5LAKVSCrhXE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=QOISjTm3Dus:AW-pCPaHN_I:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=QOISjTm3Dus:AW-pCPaHN_I:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=QOISjTm3Dus:AW-pCPaHN_I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=QOISjTm3Dus:AW-pCPaHN_I:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=QOISjTm3Dus:AW-pCPaHN_I:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=QOISjTm3Dus:AW-pCPaHN_I:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/QOISjTm3Dus" height="1" width="1"/&gt;</description></item><item><title>Budding Versus Festering Code</title><link>http://stevesmithblog.com/blog/budding-versus-festering-code/</link><pubDate>Tue, 29 Jun 2010 15:51:42 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/budding-versus-festering-code/</guid><dc:creator>ssmith</dc:creator><slash:comments>0</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;This is in response to &lt;a href="http://michaelfeathers.typepad.com/michael_feathers_blog/2010/06/festering-code-bases-and-budding-code-bases.html" rel="nofollow"&gt;Michael Feathers’ recent post on Festering Code Bases and Budding Code Bases&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Certainly the default tooling in the Visual Studio space has, until recently, made it dramatically easier to add code to an existing class than to create a new class.&amp;#160; However, tools like ReSharper have a large impact on this, and can make it extremely easy to create new classes, put them in their own files, and move those files where they are supposed to go with just a few keystrokes (and VS2010 is coming along in some of these areas as well).&amp;#160; So, I think there is a trend in the tooling to make the cost of budding less - it would be interesting to add something to the IDE that would make the cost of festering INCREASE.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/BuddingVersusFesteringCode_A6B1/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/BuddingVersusFesteringCode_A6B1/image_thumb.png" width="244" height="214" /&gt;&lt;/a&gt; Imagine an add-in that would grow more and more annoying as the size of your class increased.&amp;#160; Clippy pops up and starts to say “It looks like you’re adding code to a 3000 line class – can I recite the Single Responsibility Principle to you?”&lt;/p&gt;  &lt;p&gt;Now we might see something like the virtuous cycle it sounds like Michael Feathers is advocating for, and perhaps with enough added cost to festering codebases, we would see the de facto trend shift toward more budding-style development (and perhaps, as he notes, the problems that this might bring with it).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2UiavpWqhlL6oBk4jQ4enYdpqYo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2UiavpWqhlL6oBk4jQ4enYdpqYo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2UiavpWqhlL6oBk4jQ4enYdpqYo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2UiavpWqhlL6oBk4jQ4enYdpqYo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=ObIH47NeSmE:kZeR-7wu3Po:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=ObIH47NeSmE:kZeR-7wu3Po:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=ObIH47NeSmE:kZeR-7wu3Po:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=ObIH47NeSmE:kZeR-7wu3Po:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=ObIH47NeSmE:kZeR-7wu3Po:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=ObIH47NeSmE:kZeR-7wu3Po:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/ObIH47NeSmE" height="1" width="1"/&gt;</description></item><item><title>Disable Hibernation on Servers</title><link>http://stevesmithblog.com/blog/disable-hibernation-on-servers/</link><pubDate>Mon, 28 Jun 2010 19:33:07 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/disable-hibernation-on-servers/</guid><dc:creator>ssmith</dc:creator><slash:comments>4</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;Here’s a quick tip if you should find several GB of your system drive taken up with hiberfil.sys on a production server machine (as I recently did with a virtual server with a very small C partition) – Disable Hibernation.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Disable Hibernation&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;1. Open a command prompt as administrator&lt;/p&gt;  &lt;p&gt;2. Run this command:&lt;/p&gt;  &lt;p&gt;powercfg –h off&lt;/p&gt;  &lt;p&gt;3. Done!&lt;/p&gt;  &lt;p&gt;The hiberfil.sys file should immediately disappear.&amp;#160; This also works on desktop computers that never use hibernate, of course.&amp;#160; &lt;a href="http://forums.techarena.in/tips-tweaks/1103838.htm"&gt;Thanks to SpearMan&lt;/a&gt; for the tip.&amp;#160; I’ve only tested this on Windows Server 2008, but I’m pretty sure it will work on most modern versions of Windows (7, Vista, 2008 R2, etc.).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ps7jG8tj2xEKVRW2TESukXOilWE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ps7jG8tj2xEKVRW2TESukXOilWE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ps7jG8tj2xEKVRW2TESukXOilWE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ps7jG8tj2xEKVRW2TESukXOilWE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=ZWbSIo-LOMA:ndHaUS0eOU0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=ZWbSIo-LOMA:ndHaUS0eOU0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=ZWbSIo-LOMA:ndHaUS0eOU0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=ZWbSIo-LOMA:ndHaUS0eOU0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=ZWbSIo-LOMA:ndHaUS0eOU0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=ZWbSIo-LOMA:ndHaUS0eOU0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/ZWbSIo-LOMA" height="1" width="1"/&gt;</description></item><item><title>Default Encoding of Strings in ASP.NET MVC 2</title><link>http://stevesmithblog.com/blog/default-encoding-of-strings-in-asp-net-mvc-2/</link><pubDate>Thu, 24 Jun 2010 17:36:26 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/default-encoding-of-strings-in-asp-net-mvc-2/</guid><dc:creator>ssmith</dc:creator><slash:comments>7</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;If you have ASP.NET MVC 1 code you are moving to ASP.NET MVC 2 (and ASP.NET 4) you are likely to encounter a problem in which your application starts displaying encoded HTML on the page rather than the actual results of that HTML (e.g. you see &amp;lt;a href … /&amp;gt; instead of a hyperlink).&lt;/p&gt;  &lt;p&gt;One of the greatest features added to ASP.NET 4 is a new way to render content that is encoded by default in your .aspx/.ascx pages/views.&amp;#160; This new syntax uses &amp;lt;%: Model.SomeString %&amp;gt; instead of the ever-popular &amp;lt;%= Model.SomeString %&amp;gt; way of doing it.&amp;#160; Note the third character is now a : not an =.&amp;#160; It actually takes up a tiny bit less horizontal space – isn’t that nice of the ASP.NET team to be looking out for us that way (assuming you don’t use a fixed-width font for your programming/markup, which applies to some tiny percentage of you).&lt;/p&gt;  &lt;p&gt;So go forth, and whenever you see &amp;lt;%= in your ASP.NET 4 apps, replace it with &amp;lt;%:, and life will be good.&amp;#160; Your apps will be more secure.&amp;#160; Cross site scripting attacks will decrease.&amp;#160; Hackers will be sad.&lt;/p&gt;  &lt;p&gt;But what about your existing code that used to look like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Login Image" border="0" alt="Login Image" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/DefaultEncodingofStringsinASP.NETMVC2_BF45/image_3.png" width="161" height="92" /&gt; &lt;/p&gt;  &lt;p&gt;and now looks like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Login HTML" border="0" alt="Login HTML" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/DefaultEncodingofStringsinASP.NETMVC2_BF45/image_6.png" width="332" height="67" /&gt; &lt;/p&gt;  &lt;p&gt;This happened when you went from this code:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;%= Html.LoginLink() %&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;to this code:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;%: Html.LoginLink() %&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MvcHtmlString&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The solution to this is MvcHtmlString.&amp;#160; It’s a new class that &amp;lt;%: is aware of and if you change your helper to return one of these, you’ll get back the behavior you expect.&amp;#160; In effect, if you are returning one of these objects, you’re telling the renderer that you know what you’re doing and you’ll handle any encoding requirements and it should just display whatever you pass in.&lt;/p&gt;

&lt;p&gt;This allows you not have to think about whether to use &amp;lt;%= vs. &amp;lt;%: in your views.&amp;#160; You can (and should!) always use &amp;lt;%: in your views.&amp;#160; I say again, you should always use &amp;lt;%: in your views.&lt;/p&gt;

&lt;p&gt;So how to fix LoginLink()?&amp;#160; Simply change its signature to return an MvcHtmlString, and create one when you are returning, like so.&amp;#160; Here’s the original:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; String LoginLink(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; HtmlHelper helper)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentControllerName = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)helper.ViewContext.RouteData.Values[&lt;span style="color: #006080"&gt;&amp;quot;controller&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentActionName = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)helper.ViewContext.RouteData.Values[&lt;span style="color: #006080"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isAuthenticated = helper.ViewContext.HttpContext.Request.IsAuthenticated;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var sb = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isAuthenticated)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;Logged in as &amp;lt;span&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(helper.Encode(helper.ViewContext.HttpContext.User.Identity.Name));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/span&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;div id=\&amp;quot;loginlink\&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (currentControllerName.Equals(&lt;span style="color: #006080"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;, StringComparison.CurrentCultureIgnoreCase) &amp;amp;&amp;amp; (currentActionName.Equals(&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;, StringComparison.CurrentCultureIgnoreCase) || currentActionName.Equals(&lt;span style="color: #006080"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;, StringComparison.CurrentCultureIgnoreCase)))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(&lt;span style="color: #006080"&gt;&amp;quot; class=\&amp;quot;selected\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isAuthenticated)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(helper.ActionLink(&lt;span style="color: #006080"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(helper.ActionLink(&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Logon&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sb.ToString();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now just change the return type to MvcHtmlString and call MvcHtmlString.Create(“your string”) when you are ready to return, like so:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LoginLinkHelper&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; MvcHtmlString LoginLink(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; HtmlHelper helper)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentControllerName = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)helper.ViewContext.RouteData.Values[&lt;span style="color: #006080"&gt;&amp;quot;controller&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentActionName = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)helper.ViewContext.RouteData.Values[&lt;span style="color: #006080"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isAuthenticated = helper.ViewContext.HttpContext.Request.IsAuthenticated;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        var sb = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isAuthenticated)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;Logged in as &amp;lt;span&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(helper.Encode(helper.ViewContext.HttpContext.User.Identity.Name));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/span&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;div id=\&amp;quot;loginlink\&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (currentControllerName.Equals(&lt;span style="color: #006080"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;, StringComparison.CurrentCultureIgnoreCase) &amp;amp;&amp;amp; (currentActionName.Equals(&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;, StringComparison.CurrentCultureIgnoreCase) || currentActionName.Equals(&lt;span style="color: #006080"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;, StringComparison.CurrentCultureIgnoreCase)))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(&lt;span style="color: #006080"&gt;&amp;quot; class=\&amp;quot;selected\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isAuthenticated)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(helper.ActionLink(&lt;span style="color: #006080"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Logout&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            sb.Append(helper.ActionLink(&lt;span style="color: #006080"&gt;&amp;quot;Login&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Logon&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Account&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        sb.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; MvcHtmlString.Create(sb.ToString());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Note above in the LoginLink method that we are calling helper.Encode(…) when displaying the user’s name.&amp;#160; It’s possible that a malicious user could register with a name that includes some script tags, and depending on the registration validation or the membership API in place, it might get into our system through those means.&amp;#160; If that user then left a comment or did something else that resulted in their username being displayed on the site, it could run some malicious script that might, among other things, redirect all of our site’s users to a malicious site that could try to exploit their machine.&amp;#160; That would be bad.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Always encode untrusted user inputs.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Encoding by default is a good thing.&amp;#160; With ASP.NET 4 this is very easy to do if you just enforce the rules that &amp;lt;%= is no longer used, and is replaced everywhere with &amp;lt;%:.&amp;#160; This may result in some breaking changes from existing code that is expecting to render plain strings that contain HTML in them.&amp;#160; These can easily be fixed through the use of the MvcHtmlString class described above.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ur3TLSqlr3hCAqhlohxP8CHeU_c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ur3TLSqlr3hCAqhlohxP8CHeU_c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ur3TLSqlr3hCAqhlohxP8CHeU_c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ur3TLSqlr3hCAqhlohxP8CHeU_c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=FwCyLLLtK_E:qfe8ShNyZAQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=FwCyLLLtK_E:qfe8ShNyZAQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=FwCyLLLtK_E:qfe8ShNyZAQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=FwCyLLLtK_E:qfe8ShNyZAQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=FwCyLLLtK_E:qfe8ShNyZAQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=FwCyLLLtK_E:qfe8ShNyZAQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/FwCyLLLtK_E" height="1" width="1"/&gt;</description></item><item><title>Tagging Releases in Source Control</title><link>http://stevesmithblog.com/blog/tagging-releases-in-source-control/</link><pubDate>Wed, 23 Jun 2010 14:31:00 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/tagging-releases-in-source-control/</guid><dc:creator>ssmith</dc:creator><slash:comments>2</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;A best practice when you’re using source control is to tag your releases.&amp;#160; What does this mean, exactly?&amp;#160; If you’re following the relatively standard non-distributed source control repository folder structure of having root folders for:&lt;/p&gt;  &lt;p&gt;branches   &lt;br /&gt;tags    &lt;br /&gt;trunk&lt;/p&gt;  &lt;p&gt;then it means simply making a copy of the current state of the system when you did your release.&amp;#160; Here’s how to do it using Subversion (SVN) and the TortoiseSVN client, both popular free tools for source control management.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: Test and Deploy Your Application&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Do whatever it is you do to deploy your application.&amp;#160; Maybe you create an EXE package.&amp;#160; Maybe you FTP a web site to production.&amp;#160; Whatever it is, get your source code into the final state it needs to be in, and then do your deployment.&lt;/p&gt;  &lt;p&gt;If the deployment doesn’t work, don’t go past this step.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 2: Tag Your Current Trunk&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Assuming that you re deploying from the trunk of your source control repository, and that it’s your working copy (both relatively standard assumptions but certainly not 100% true for all shops) then the following steps should work for you.&lt;/p&gt;  &lt;p&gt;First, go to the root of your working copy and select Branch/tag from the TortoiseSVN menu in Windows Explorer.&amp;#160; See Figure 1.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Figure 1 – Select Branch/tag…&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TortoiseSVN Menu" border="0" alt="TortoiseSVN Menu" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/TaggingReleasesinSourceControl_93FB/image_3.png" width="324" height="367" /&gt; &lt;/p&gt;  &lt;p&gt;Next, you want to fill in the dialog like in Figure 2 below.&amp;#160; You’re copying from the trunk, which should be the default for the first URL (From WC at URL:).&amp;#160; Your To URL you will need to set.&amp;#160; It’s a good idea to use a datetime that will sort alphanumerically, like &lt;strong&gt;YYYYMMDDSomething&lt;/strong&gt;.&amp;#160; Since we might use tags for things other than deployments, I use &lt;strong&gt;YYMMDDDeploy&lt;/strong&gt;.&amp;#160; If you end up having more than one deployment on a given date, you can always add an 01, 02, 03 or something to the end of the string.&amp;#160; This is basically just a foldername – you can do whatever you want with it but it’s good to have a standard and stick to it.&amp;#160; “Release” is also common.&lt;/p&gt;  &lt;p&gt;If your working copy is what you just deployed, it’s best to select that for the Create copy in the repository from: option.&amp;#160; However, if you’ve just checked in or done an update and you know your working copy is the same as the latest in the trunk, you could select HEAD revision in the repository.&amp;#160; Just be careful if you do this and you work on a team – if someone else does a checkin before you’re done with your tagging operation, you could end up with stuff in your tagged version of the code that didn’t really go into the deployment.&amp;#160; Working copy is safer.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Figure 2 – Copy (Branch / Tag) window&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/TaggingReleasesinSourceControl_93FB/SNAGHTMLf71e9ca3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Copy Branch/Tag Window" border="0" alt="Copy Branch/Tag Window" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/TaggingReleasesinSourceControl_93FB/SNAGHTMLf71e9ca3_thumb.png" width="352" height="383" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you do end up with a different version in your working copy than what was deployed, you can always use the Specific revision in repository option to select the actual revision number that corresponded to the deployment.&lt;/p&gt;  &lt;p&gt;You want to be sure to leave the Switch working copy to new branch/tag checkbox unchecked.&amp;#160; Generally tags are meant to be snapshots, not something that you commit work to.&amp;#160; If you end up needing to modify stuff in a tag, you should copy it into a branch and do the work there, then merge it into the trunk, then deploy it, and tag the new deployment.&lt;/p&gt;  &lt;p&gt;Once you’re ready, click OK and you should see something like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Tortoise SVN Copy Window" border="0" alt="Tortoise SVN Copy Window" src="http://stevesmithblog.com/files/media/image/WindowsLiveWriter/TaggingReleasesinSourceControl_93FB/image_6.png" width="419" height="208" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Adding tags is valuable because it lets you identify the exact version of your software that corresponds with a given release or deployment.&amp;#160; If bugs occur, you can review the tagged copy of your source to identify the bug, then create a branch in which to fix it (or just fix it in the trunk if it’s simple).&amp;#160; Without tags, if any significant work is done between releases, it can be difficult to recreate an environment that corresponds to the one a customer is using when bugs are found.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ss5A2gVC4Xy2CYSfGAsqR0HG2Vs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ss5A2gVC4Xy2CYSfGAsqR0HG2Vs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ss5A2gVC4Xy2CYSfGAsqR0HG2Vs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ss5A2gVC4Xy2CYSfGAsqR0HG2Vs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=V8Jj3BEeLbo:hawz5aJmLBE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=V8Jj3BEeLbo:hawz5aJmLBE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=V8Jj3BEeLbo:hawz5aJmLBE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=V8Jj3BEeLbo:hawz5aJmLBE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=V8Jj3BEeLbo:hawz5aJmLBE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=V8Jj3BEeLbo:hawz5aJmLBE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/V8Jj3BEeLbo" height="1" width="1"/&gt;</description></item><item><title>Great Uses of Using Statement in C#</title><link>http://stevesmithblog.com/blog/great-uses-of-using-statement-in-c/</link><pubDate>Mon, 21 Jun 2010 13:32:00 GMT</pubDate><guid isPermaLink="true">http://stevesmithblog.com/blog/great-uses-of-using-statement-in-c/</guid><dc:creator>ssmith</dc:creator><slash:comments>14</slash:comments><category domain="http://stevesmithblog.com/blog/">Blog</category><description>&lt;p&gt;In my last post about &lt;a href="http://stevesmithblog.com/blog/testing-email-sending/"&gt;testing emails in .NET&lt;/a&gt;, I noted the use of the using statement to ensure safe usage of the IDisposable SmtpClient and MailMessage objects.&amp;#160; This is the typical usage of the using statement, but you can take advantage of this statement’s behavior for other scenarios as well, resulting in cleaner code.&lt;/p&gt;  &lt;p&gt;Consider the scenario where you want to perform some kind of pre- and post- processing around an arbitrary block of code.&amp;#160; The simplest scenario I know of is when you want to time some code, using the stopwatch class.&amp;#160; If you want to perform basic stopwatch usage, you can write some code like this (borrowed from the stopwatch MSDN docs):&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; BasicStopWatchUsage()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Basic StopWatch Used: &amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var stopWatch = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Stopwatch();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    stopWatch.Start();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    Thread.Sleep(3000);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    stopWatch.Stop();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    TimeSpan ts = stopWatch.Elapsed;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; elapsedTime = String.Format(&lt;span style="color: #006080"&gt;&amp;quot;{0:00}:{1:00}:{2:00}.{3:00}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;                                       ts.Hours, ts.Minutes, ts.Seconds,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;                                       ts.Milliseconds/10);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    Console.WriteLine(elapsedTime, &lt;span style="color: #006080"&gt;&amp;quot;RunTime&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This works, and of course the Thread.Sleep(3000); is where our actual work would go.&amp;#160; If our actual work is a relatively small amount of code, it can easily be lost in the clutter that comprises our stopwatch profiling code.&amp;#160; We can rewrite the above code like so if we move our profiling code into an IDisposable class:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UsingStopWatchUsage()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;ConsoleAutoStopWatch Used: &amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ConsoleAutoStopWatch())&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Thread.Sleep(3000);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And of course, even the Console.WriteLine could be moved into the ConsoleAutoStopWatch class’s constructor if we wished to do so.&amp;#160; The ConsoleAutoStopWatch, so named because it’s coupled to the Console (you could easily create similar implementations that use your favorite logging component, or dependency-inject the outputter for the class), is shown here:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#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"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ConsoleAutoStopWatch : IDisposable&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; Stopwatch _stopWatch;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ConsoleAutoStopWatch()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _stopWatch = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Stopwatch();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _stopWatch.Start();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _stopWatch.Stop();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        TimeSpan ts = _stopWatch.Elapsed;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; elapsedTime = String.Format(&lt;span style="color: #006080"&gt;&amp;quot;{0:00}:{1:00}:{2:00}.{3:00}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;                                           ts.Hours, ts.Minutes, ts.Seconds,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;                                           ts.Milliseconds / 10);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Console.WriteLine(elapsedTime, &lt;span style="color: #006080"&gt;&amp;quot;RunTime&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;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: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now anywhere you need to profile a small block of code or a method call, you can simply wrap it in a using(new ConsoleAutoStopWatch()) {…} block.&amp;#160; Note also that since our code doesn’t require any reference to the ConsoleAutoStopWatch class, we don’t even set it to a variable instance.&amp;#160; It’s sufficient to simply new it up within the using().&lt;/p&gt;

&lt;p&gt;You can imagine other scenarios where you may have some pre- and post- processing you need to do that is independent of the work being done.&amp;#160; In these scenarios, you can clean up your code and separate your concerns effectively through this kind of usage of the IDisposable pattern and the using() statement.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="http://feeds.feedburner.com/StevenSmith" rel="nofollow"&gt;Subscribe to Steve’s blog here&lt;/a&gt;&lt;/em&gt;&lt;em&gt;; follow Steve at &lt;/em&gt;&lt;a href="http://twitter.com/ardalis" rel="nofollow"&gt;&lt;em&gt;http://twitter.com/ardalis&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_HrrjD6G65EFrS4RmKMPh2xnTMU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_HrrjD6G65EFrS4RmKMPh2xnTMU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_HrrjD6G65EFrS4RmKMPh2xnTMU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_HrrjD6G65EFrS4RmKMPh2xnTMU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=riz-IyPudyA:EIZWyFWK9Aw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=riz-IyPudyA:EIZWyFWK9Aw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=riz-IyPudyA:EIZWyFWK9Aw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=riz-IyPudyA:EIZWyFWK9Aw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.stevesmithblog.com/~ff/StevenSmith?a=riz-IyPudyA:EIZWyFWK9Aw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/StevenSmith?i=riz-IyPudyA:EIZWyFWK9Aw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/StevenSmith/~4/riz-IyPudyA" height="1" width="1"/&gt;</description></item></channel></rss>
