<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JohnnyCoder &#187; ASP.NET</title>
	<atom:link href="http://johnnycoder.com/blog/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnnycoder.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 10 Apr 2012 00:14:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Deploying ASP.NET Web Applications</title>
		<link>http://johnnycoder.com/blog/2010/04/07/deploying-asp-net-web-applications/</link>
		<comments>http://johnnycoder.com/blog/2010/04/07/deploying-asp-net-web-applications/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 18:07:49 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Screencasts]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/04/07/deploying-asp-net-web-applications/</guid>
		<description><![CDATA[In this episode, Noah and I explain how to use Web Deployment Projects to deploy your web application. This screencast will get you up and running, but in a future screencast, we discuss more advanced topics like excluding files, swapping out the right config files per environment, and alternate solution configurations.&#160; This screencast (and the [...]]]></description>
			<content:encoded><![CDATA[<p>In this episode, <a href="http://www.fairwaytech.com/blog/NoahH/Default.aspx">Noah</a> and I explain how to use Web Deployment Projects to deploy your web application. This screencast will get you up and running, but in a future screencast, we discuss more advanced topics like excluding files, swapping out the right config files per environment, and alternate solution configurations.&#160; </p>
<p><object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=10294153&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=10294153&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>    </p>
<p>This screencast (and the next) are based on a write-up I did about <a href="http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/">ASP.NET Web Application deployment with Web Deployment Projects</a> a while back.&#160; Multi-media knowledge sharing.&#160; You have to love it!</p>
<p><em>This is the first video hosted on Vimeo.&#160; What do you think?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/04/07/deploying-asp-net-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Membership Provider Setup</title>
		<link>http://johnnycoder.com/blog/2010/04/07/asp-net-membership-provider-setup/</link>
		<comments>http://johnnycoder.com/blog/2010/04/07/asp-net-membership-provider-setup/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 17:51:34 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Screencasts]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/04/07/asp-net-membership-provider-setup/</guid>
		<description><![CDATA[In this screencast, Noah and I show you how to quickly get started with the ASP.NET Membership Provider.&#160; We’ll take you through basic features and setup and walk you through membership table creation with the ASP.NET SQL Server Wizard. I’ve written about the ASP.NET Membership Provider and setup before.&#160; If you missed the post, this [...]]]></description>
			<content:encoded><![CDATA[<p>In this screencast, <a href="http://www.fairwaytech.com/blog/NoahH/Default.aspx">Noah</a> and I show you how to quickly get started with the ASP.NET Membership Provider.&#160; We’ll take you through basic features and setup and walk you through membership table creation with the ASP.NET SQL Server Wizard. </p>
<p>I’ve written about <a href="http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/">the ASP.NET Membership Provider and setup before</a>.&#160; If you missed the post, this introductory video may be for you. </p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:54329a19-2455-421f-8225-6ae0ec0b554e" class="wlWriterEditableSmartContent">
<div><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/wek-blnTo2w&amp;hl=en_US&amp;fs=1&amp;&amp;hl=en"></param><embed src="http://www.youtube.com/v/wek-blnTo2w&amp;hl=en_US&amp;fs=1&amp;&amp;hl=en" type="application/x-shockwave-flash" width="425" height="355"></embed></object></div>
</div>
<p>&#160;</p>
<p><em>This is one of our first screencasts.&#160; If you have feedback, I’d love to hear it.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/04/07/asp-net-membership-provider-setup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom Profile Provider with Web Deployment Project</title>
		<link>http://johnnycoder.com/blog/2010/04/02/custom-profile-provider-with-web-deployment-project/</link>
		<comments>http://johnnycoder.com/blog/2010/04/02/custom-profile-provider-with-web-deployment-project/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 00:36:58 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Deployment]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/04/02/custom-profile-provider-with-web-deployment-project/</guid>
		<description><![CDATA[I wrote about implementing a custom profile provider inside of your ASP.NET MVC application yesterday. If you haven’t read the article, don’t sweat it.&#160; Most of the stuff I write is rubbish anyway. Since you have joined me today, though, I might as well offer up a little tip: you can run into trouble, like [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote about <a href="http://johnnycoder.com/blog/2010/04/01/asp-net-mvc-custom-profile-provider/">implementing a custom profile provider inside of your ASP.NET MVC application</a> yesterday. If you haven’t read the article, don’t sweat it.&#160; Most of the stuff I write is rubbish anyway. <img src='http://johnnycoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Since you have joined me today, though, I might as well offer up a little tip: you can run into trouble, like I did, if you enable your custom profile provider inside of an application which is deployed using a <a href="http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/">Web Deployment Project</a>.&#160; Everything will run great on your local machine and you’ll probably take an early lunch because you got the code running in no time flat and the build server is happy and all tests pass and, gosh, maybe you’ll just cut out early because it is Friday after all.&#160; But then the first user hits the integration machine and, that’s right, yellow screen of death. Lucky you, just as you’re walking out the door, the user kindly sends the exception message and stack trace:</p>
<blockquote><p>Value cannot be null. Parameter name: type Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p>
<p><strong>Stack Trace:</strong>       <br />[ArgumentNullException: Value cannot be null. Parameter name: type] System.Activator.CreateInstance(Type type, Boolean nonPublic) +2796915 System.Web.Profile.ProfileBase.CreateMyInstance(String username, Boolean isAuthenticated) +76 System.Web.Profile.ProfileBase.Create(String username, Boolean isAuthenticated) +312</p>
</blockquote>
<p>User error?&#160; Not this time. Damn! </p>
<p>One hour later… you notice the harmless “Treat as library component (remove the App_Code.compiled file)” setting on the Output Assemblies Tab of your Web Deployment Project.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/04/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/04/image_thumb.png" width="553" height="178" /></a> </p>
<p>You have no idea why, but you uncheck it.&#160; You test and everything works great both locally and on the integration machine.&#160; Application users think you’re the best and you’re still going to catch the last half hour of happy hour.&#160; Happy Friday.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/04/02/custom-profile-provider-with-web-deployment-project/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Custom Profile Provider</title>
		<link>http://johnnycoder.com/blog/2010/04/01/asp-net-mvc-custom-profile-provider/</link>
		<comments>http://johnnycoder.com/blog/2010/04/01/asp-net-mvc-custom-profile-provider/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 00:36:53 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/04/01/asp-net-mvc-custom-profile-provider/</guid>
		<description><![CDATA[It’s been a long while since I last used the ASP.NET Profile provider. It’s a shame, too, because it just works with very little development effort: Membership tables installed? Check. Profile enabled in web.config? Check. SqlProfileProvider connection string set? Check.&#160; Profile properties defined in said web.config file? Check. Write code to set value, read value, [...]]]></description>
			<content:encoded><![CDATA[<p>It’s been a long while since I last used the ASP.NET Profile provider. It’s a shame, too, because it just works with very little development effort:</p>
<ol>
<ol>
<li>Membership tables installed? Check. </li>
<li>Profile enabled in web.config? Check. </li>
<li>SqlProfileProvider connection string set? Check.&#160; </li>
<li>Profile properties defined in said web.config file? Check. </li>
<li>Write code to set value, read value, build and test. Check. Check. Check.&#160; </li>
</ol>
</ol>
<p>Yep, I thought the built-in Profile stuff was pure gold until I noticed how the user-based information is persisted to the database. It’s stored as xml and, well, that was going to be trouble if I ever wanted to query the profile data.&#160; So, I have avoided the super-easy-to-use ASP.NET Profile provider ever since, until this week, when I decided I could use it to store user-specific properties which I am 99% positive I’ll never need to query against ever.&#160; </p>
<p>I opened up my ASP.NET MVC application, completed steps 1-4 (above) in about 3 minutes, started writing my profile get/set code and that’s where the plan broke down.&#160; Oh yeah. That’s right.&#160; <strong>Visual Studio auto-generates a strongly-type Profile reference for web site projects but not for ASP.NET MVC or Web Applications.</strong>&#160; Bummer. So, I went through the steps of getting a customer profile provider working in my ASP.NET MVC application:</p>
<p>First, I defined a CurrentUser routine and my profile properties in a custom Profile class like so:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b1ea6a27-cda6-4da0-9fbe-64d049336b1c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #fff; overflow: auto">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">using</span> System.Web.Profile;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Web.Security;</li>
<li><span style="color:#0000ff">using</span> Project.Core;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">namespace</span> Project.Web.Context</li>
<li style="background: #f3f3f3">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">MemberPreferencesProfile</span> : <span style="color:#2b91af">ProfileBase</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">static</span> <span style="color:#0000ff">public</span> <span style="color:#2b91af">MemberPreferencesProfile</span> CurrentUser</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">get</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">return</span> (<span style="color:#2b91af">MemberPreferencesProfile</span>) </li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Create(<span style="color:#2b91af">Membership</span>.GetUser().UserName); </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">public</span> Enums.PresenceViewModes? ViewMode</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">get</span> { <span style="color:#0000ff">return</span> ((Enums.PresenceViewModes)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;( <span style="color:#0000ff">base</span>[<span style="color:#a31515">&quot;ViewMode&quot;</span>] ?? Enums.PresenceViewModes.Category)); }</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">set</span> { <span style="color:#0000ff">base</span>[<span style="color:#a31515">&quot;ViewMode&quot;</span>] = <span style="color:#0000ff">value</span>; Save(); }</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;}</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>And then I replaced the existing profile configuration web.config with the following:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5cd1719f-7d0d-480c-9a2b-bda1e6f9dfcf" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #fff; overflow: auto">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">profile</span><span style="color:#0000ff"> </span><span style="color:#ff0000">enabled</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">true</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">defaultProvider</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">MvcSqlProfileProvider</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">inherits</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Project.Web.Context.MemberPreferencesProfile</span>&quot;<span style="color:#0000ff">&gt;&#160;&#160;&#160;&#160;&#160;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">MvcSqlProfileProvider</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Profile.SqlProfileProvider, System.Web, </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;<span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">profile</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>Notice that profile is enabled, I’ve defined the defaultProvider and profile is now inheriting from my custom MemberPreferencesProfile class.&#160; </p>
<p>Finally, I am now able to set and get profile property values nearly the same way as I did with website projects:</p>
</p>
</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6b23f713-39a4-45e9-a772-9f332405c8bb" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #fff; overflow: auto">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap">
<li>viewMode = <span style="color:#2b91af">MemberPreferencesProfile</span>.CurrentUser.ViewMode;</li>
<li style="background: #f3f3f3"><span style="color:#2b91af">MemberPreferencesProfile</span>.CurrentUser.ViewMode = viewMode;</li>
</ol></div>
</p></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/04/01/asp-net-mvc-custom-profile-provider/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Deploy ASP.NET Web Applications with Web Deployment Projects</title>
		<link>http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/</link>
		<comments>http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 23:35:26 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/</guid>
		<description><![CDATA[One may quickly build and deploy an ASP.NET web application via the Publish option in Visual Studio.&#160; This option works great for most simple deployment scenarios but it won’t always cut it.&#160; Let’s say you need to automate your deployments. Or you have environment-specific configuration settings. Or you need to execute pre/post build operations when [...]]]></description>
			<content:encoded><![CDATA[<p>One may quickly build and deploy an ASP.NET web application via the Publish option in Visual Studio.&#160; This option works great for most simple deployment scenarios but it won’t always cut it.&#160; Let’s say you need to automate your deployments. Or you have environment-specific configuration settings. Or you need to execute pre/post build operations when you do your builds.&#160; If so, you should consider using Web Deployment Projects. </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb3.png" width="305" height="286" /></a> </p>
<p>The Web Deployment Project type doesn’t come out-of-the-box with Visual Studio 2008.&#160; You’ll need to <a href="http://www.microsoft.com/downloads/details.aspx?familyId=0AA30AE8-C73B-4BDD-BB1B-FE697256C459&amp;displaylang=en">Download Visual Studio® 2008 Web Deployment Projects – RTW</a> and install if you want to follow along with this tutorial.</p>
<p>I’ve created a shiny new ASP.NET MVC project.&#160; Web Deployment Projects work with websites, web applications and MVC projects so feel free to go with any web project type you’d like.&#160; </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb4.png" width="381" height="333" /></a> </p>
<p>Once your web application is in place, it’s time to add the Web Deployment project.&#160; You can hunt and peck around the File &gt; New &gt; New Project… dialogue as long as you’d like, but you aren’t going to find what you need.&#160; Instead, select the web project and then choose the “Add Web Deployment Project…” hiding behind the Build menu option.    </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb5.png" width="305" height="286" /></a> </p>
<p>I prefer to name my projects based on the environment in which I plan to deploy.&#160; In this case, I’ll be rolling to the QA machine.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb6.png" width="538" height="224" /></a> </p>
<p>Don’t expect too much to happen at this point.&#160; A seemingly empty project with a funny icon will be added to your solution.&#160; That’s it.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb7.png" width="381" height="333" /></a> </p>
<p>I want to take a minute and talk about configuration settings before we continue.&#160; Some of the common settings which might change from environment to environment are appSettings, connectionStrings and mailSettings.&#160; Here’s a look at my updated web.config:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6e80d125-9254-4d01-b57d-cefd3c119a28" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">appSettings</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">key</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">MvcApplication293.Url</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">value</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">http://localhost:50596/</span>&quot;<span style="color:#0000ff"> /&gt;&#160;&#160;&#160;&#160;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">appSettings</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff"></span></li>
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionString</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">data source=.&#92;SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">providerName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Data.SqlClient</span>&quot;<span style="color:#0000ff">/&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">system.net</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">mailSettings</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">smtp</span><span style="color:#0000ff"> </span><span style="color:#ff0000">from</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">sender@application.com</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;</span><span style="color:#a31515">network</span><span style="color:#0000ff"> </span><span style="color:#ff0000">host</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">server.com</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">userName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">username</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">password</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">password</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">port</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">587</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">defaultCredentials</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;<span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">smtp</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">mailSettings</span><span style="color:#0000ff">&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">system.net</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>I want to update these values prior to deploying to the QA environment.&#160; There are variations to this approach, but I like to maintain environment-specific settings for each of the web.config sections in the Config/[Environment] project folders.&#160; I’ve provided a screenshot of the QA environment settings below.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb8.png" width="381" height="503" /></a></p>
<p>It may be obvious what one should include in each of the three files.&#160; Basically, it is a copy of the associated web.config section with updated setting values.&#160; For example, the AppSettings.config file may include a reference to the QA web url, the DB.config would include the QA database server and login information and the StmpSettings.config would include a QA Stmp server and user information. </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:73477ed5-06c1-4639-a9bb-efe992516be4" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;?</span><span style="color:#a31515">xml</span><span style="color:#0000ff"> </span><span style="color:#ff0000">version</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">1.0</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">encoding</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">utf-8</span>&quot;<span style="color:#0000ff"> ?&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">appSettings</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">key</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">MvcApplication293.Url</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">value</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">http://qa.MvcApplicatinon293.com/</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">appSettings</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p align="left"><em>AppSettings.config</em>&#160;</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b0df7d58-f346-43f6-ae3d-48e486e294bb" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;?</span><span style="color:#a31515">xml</span><span style="color:#0000ff"> </span><span style="color:#ff0000">version</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">1.0</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">encoding</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">utf-8</span>&quot;<span style="color:#0000ff"> ?&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionString</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">server=QAServer;integrated security=SSPI;database=MvcApplication293</span>&quot;<span style="color:#0000ff"> </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">providerName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Data.SqlClient</span>&quot;<span style="color:#0000ff">/&gt;&#160;&#160;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p align="left"><em>Db.config</em>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cc44c343-2e39-40e2-a69a-de3808235358" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;?</span><span style="color:#a31515">xml</span><span style="color:#0000ff"> </span><span style="color:#ff0000">version</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">1.0</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">encoding</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">utf-8</span>&quot;<span style="color:#0000ff"> ?&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">smtp</span><span style="color:#0000ff"> </span><span style="color:#ff0000">from</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">qasender@application.com</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&#160;&#160;&lt;</span><span style="color:#a31515">network</span><span style="color:#0000ff"> </span><span style="color:#ff0000">host</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">qaserver.com</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">userName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">qausername</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">password</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">qapassword</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">port</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">587</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">defaultCredentials</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;<span style="color:#0000ff">/&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">smtp</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p align="left"><em>SmtpSettings.config</em>&#160;</p>
<p>I think our web project is ready to deploy.&#160; Now, it’s time to concentrate on the Web Deployment Project itself.&#160; Right-click on the project file and open the Property Pages.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb9.png" width="268" height="290" /></a> </p>
<p>The first thing to call out is the Configuration dropdown.&#160; I only deploy a project which is built in Release Mode so I only setup the Web Deployment Project for this mode.&#160; (This is when you change the Configuration selection to “Release.”)&#160; I typically keep the Output Folder default value – .\Release\.&#160; When the application is built, all artifacts will be dropped in the .\Release\ folder relative to the Web Deployment Project root.&#160; The final option may be up for some debate.&#160; I like to roll out updatable websites so I select the “Allow this precompiled site to be updatable” option.&#160; I really do like to follow standard SDLC processes when I release my software but there are those times when you just have to make a hotfix to production and I like to keep this option open if need be.&#160; If you are strongly opposed to this idea, please, by all means, don’t check the box.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb10.png" width="644" height="384" /></a> </p>
<p>The next tab is boring.&#160; I don’t like to deploy a crazy number of DLLs so I merge all outputs to a single assembly.&#160; Again, you may have another option and feel free to change this selection if you so wish.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb11.png" width="644" height="381" /></a> </p>
<p>If you follow my lead, take care when choosing a single assembly name.&#160; The Assembly Name can not be the same as the website or any other project in your solution otherwise you’ll receive a circular reference build error.&#160; In other words, I can’t name the assembly MvcApplication293 or my output window would start yelling at me.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb12.png" width="698" height="199" /></a></p>
<p>Remember when we called out our QA configuration files?&#160; Click on the Deployment tab and you’ll see how where going to use them.&#160; Notice the Web.config file section replacements value.&#160; All this does is swap called out web.config sections with the content of the Config\QA\* files.&#160; You can reduce or extend this list as you deem fit.&#160; </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb13.png" width="644" height="384" /></a> </p>
<p>Did you see the “Use external configuration source file” option?&#160; You know how you can point any of your web.config sections to an external file via the configSource attribute?&#160; This option allows you to leverage that technique and instead of replacing the content of the sections, you will replace the configSource attribute value instead.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:baa404d2-9f97-4522-b341-031fb3520a1b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">appSettings</span><span style="color:#0000ff"> </span><span style="color:#ff0000">configSource</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;AppSettings.config</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Go ahead and Apply your changes.&#160; I’d like to take a look at the project file we just updated.&#160; Right-click on the Web Deployment Project and select “Open Project File.”</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb14.png" width="268" height="290" /></a> </p>
<p>One of the first configuration blocks reflects core Release build settings.&#160; There are a couple of points I’d like to call out here:</p>
<ul>
<li>DebugSymbols=false ensures the compilation debug attribute in your web.config is flipped to false as part of build process.&#160; There’s <a href="http://msdn.microsoft.com/en-us/library/aa479568.aspx">some crumby (more likely old) documentation</a> which implies you need a ToggleDebugCompilation task to make this happen.&#160; Nope. Just make sure the DebugSymbols is set to false.&#160; </p>
</li>
<li>EnableUpdateable implies a single dll for the web application rather than a dll for each object and and empty view file. I think updatable applications are cleaner and include the benefit (or risk based on your perspective) that portions of the application can be updated directly on the server.&#160; I called this out earlier but I wanted to reiterate. </li>
</ul>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fa5c596b-d092-48ef-9e00-eca5ac0fe4a5" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff"> &lt;</span><span style="color:#a31515">PropertyGroup</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Condition</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff"> &#39;$(Configuration)|$(Platform)&#39; == &#39;Release|AnyCPU&#39; </span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">DebugSymbols</span><span style="color:#0000ff">&gt;</span>false<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">DebugSymbols</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">OutputPath</span><span style="color:#0000ff">&gt;</span>.&#92;Release<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">OutputPath</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">EnableUpdateable</span><span style="color:#0000ff">&gt;</span>true<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">EnableUpdateable</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">UseMerge</span><span style="color:#0000ff">&gt;</span>true<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UseMerge</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">SingleAssemblyName</span><span style="color:#0000ff">&gt;</span>MvcApplication293<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">SingleAssemblyName</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">DeleteAppCodeCompiledFiles</span><span style="color:#0000ff">&gt;</span>true<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">DeleteAppCodeCompiledFiles</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">UseWebConfigReplacement</span><span style="color:#0000ff">&gt;</span>true<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UseWebConfigReplacement</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ValidateWebConfigReplacement</span><span style="color:#0000ff">&gt;</span>true<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ValidateWebConfigReplacement</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">DeleteAppDataFolder</span><span style="color:#0000ff">&gt;</span>true<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">DeleteAppDataFolder</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">PropertyGroup</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>The next section is self-explanatory.&#160; The content merely reflects the replacement value you provided via the Property Pages. </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6b151b21-2c85-418a-a733-da31e833be88" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ItemGroup</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Condition</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">&#39;$(Configuration)|$(Platform)&#39; == &#39;Release|AnyCPU&#39;</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;AppSettings.config</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span>appSettings<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;Db.config</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span>connectionStrings<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;SmtpSettings.config</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span>system.net/mailSettings/smtp<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ItemGroup</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>You’ll want to extend the ItemGroup section to include the files you wish to exclude from the build.&#160; The sample ExcludeFromBuild nodes exclude all obj, svn, csproj, user, pdb artifacts from the build. Enough though they files aren’t included in your web project, you’ll need to exclude them or they’ll show up along with required deployment artifacts.&#160; </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6269dc70-827d-4b6e-ad95-53bc82faefbd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff"> &lt;</span><span style="color:#a31515">ItemGroup</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Condition</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">&#39;$(Configuration)|$(Platform)&#39; == &#39;Release|AnyCPU&#39;</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;AppSettings.config</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span>appSettings<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;Db.config</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span>connectionStrings<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Config&#92;QA&#92;SmtpSettings.config</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span>system.net/mailSettings/smtp<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Section</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">WebConfigReplacementFiles</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;obj&#92;**&#92;*.*</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;**&#92;.svn&#92;**&#92;*.*</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;**&#92;.svn&#92;**&#92;*</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;**&#92;*.csproj</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;**&#92;*.user</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;bin&#92;*.pdb</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">ExcludeFromBuild</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(SourceWebPhysicalPath)&#92;Notes.txt</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ItemGroup</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Pre/post build and Pre/post merge tasks are added to the final code block.&#160; By default, your project file should look like the following – a completely commented out section.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a3546d2d-a9e9-45d0-95de-a4ae07bbde27" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff"> &lt;!&#8211;</span><span style="color:#008000"> To modify your build process, add your task inside one of </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">the targets below and uncomment it. Other similar extension </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">points exist, see Microsoft.WebDeployment.targets.</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;BeforeBuild&quot;&gt;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;BeforeMerge&quot;&gt;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;AfterMerge&quot;&gt;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;AfterBuild&quot;&gt;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000"></span><span style="color:#0000ff">&#8211;&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>Update the section to remove all temporary Config folders and files after the build.&#160; </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6174b7ae-5bd4-4ad7-961c-94d13aa69404" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;!&#8211;</span><span style="color:#008000"> To modify your build process, add your task inside one of</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">the targets below and uncomment it. Other similar extension </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">points exist, see Microsoft.WebDeployment.targets.&#160;&#160;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;BeforeMerge&quot;&gt;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;AfterMerge&quot;&gt;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;&#160;&#160;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#008000">&lt;Target Name=&quot;BeforeBuild&quot;&gt;&#160;&#160;&#160;</span></li>
<li>&#160;&#160;<span style="color:#008000">&lt;/Target&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000"></span><span style="color:#0000ff">&#8211;&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">Target</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AfterBuild</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;!&#8211;</span><span style="color:#008000"> WebConfigReplacement requires the Config files. Remove after build. </span><span style="color:#0000ff">&#8211;&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">RemoveDir</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Directories</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">$(OutputPath)&#92;Config</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Target</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>That’s it for setup.&#160; Save the project file, flip the solution to Release Mode and build.&#160; If there’s an issue, consult the Output window for details.&#160; If all went well, you will find your deployment artifacts in your Web Deployment Project folder like so.    </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb15.png" width="525" height="105" /></a> </p>
<p>Both the code source and published application will be there. Inside the Release folder you will find your “published files” and you’ll notice the Config folder is no where to be found.&#160; In the Source folder, all project files are found with the exception of the items which were excluded from the build.</p>
<p>I’ll wrap up this tutorial by calling out a little Web Deployment pet peeve of mine: there doesn’t appear to be a way to add an existing web deployment project to a solution.&#160; The best I can come up with is create a new web deployment project and then copy and paste the contents of the existing project file into the new project file.&#160; It’s not a big deal but it bugs me.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:2eb7ea6d-14cc-4335-8247-1e148a0d3da0" class="wlWriterEditableSmartContent">
<p> <a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/mvcapplication293.zip" target="_blank">Download the Solution</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>ASP.NET Meta Keywords and Description</title>
		<link>http://johnnycoder.com/blog/2010/01/05/aspnet-meta-keywords-and-description/</link>
		<comments>http://johnnycoder.com/blog/2010/01/05/aspnet-meta-keywords-and-description/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 17:11:23 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/01/05/aspnet-meta-keywords-and-description/</guid>
		<description><![CDATA[Some of the ASP.NET 4 improvements around SEO are neat.&#160; The ASP.NET 4 Page.MetaKeywords and Page.MetaDescription properties, for example, are a welcomed change.&#160; There’s nothing earth-shattering going on here – you can now set these meta tags via your Master page’s code behind rather than relying on updates to your markup alone.&#160; It isn’t difficult [...]]]></description>
			<content:encoded><![CDATA[<p>Some of the ASP.NET 4 improvements around SEO are neat.&#160; The <a href="http://weblogs.asp.net/scottgu/archive/2010/01/05/asp-net-4-seo-improvements-vs-2010-and-net-4-0-series.aspx">ASP.NET 4 Page.MetaKeywords and Page.MetaDescription properties</a>, for example, are a welcomed change.&#160; There’s nothing earth-shattering going on here – you can now set these meta tags via your Master page’s code behind rather than relying on updates to your markup alone.&#160; It isn’t difficult to manage meta keywords and descriptions without these ASP.NET 4 properties but I still appreciate the attention SEO is getting.&#160; It’s nice to get gentle reminder via new coding features that some of the more subtle aspects of one’s application deserve thought and attention too.&#160; </p>
<p>For the record, this is how I currently manage my meta:    </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ac73426b-7c10-4b24-b793-734651a91082" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 400px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">meta</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">=&quot;keywords&quot;</span> </li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#ff0000">content</span><span style="color:#0000ff">=&quot;</span><span style="background:#ffee62">&lt;%</span>= Html.Encode(ConfigurationManager.AppSettings[&quot;Meta.Keywords&quot;]) <span style="background:#ffee62">%&gt;</span><span style="color:#0000ff">&quot;</span> <span style="color:#0000ff">/&gt;</span></li>
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">meta</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">=&quot;description&quot;</span> </li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#ff0000">content</span><span style="color:#0000ff">=&quot;</span><span style="background:#ffee62">&lt;%</span>= Html.Encode(ConfigurationManager.AppSettings[&quot;Meta.Description&quot;]) <span style="background:#ffee62">%&gt;</span><span style="color:#0000ff">&quot;</span> <span style="color:#0000ff">/&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>All Master pages assume the same keywords and description values as defined by the application settings.&#160; Nothing fancy. Nothing dynamic. But it’s manageable.&#160; It works, but I’m looking forward to the new way in ASP.NET 4.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/01/05/aspnet-meta-keywords-and-description/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Started with ASP.NET Membership, Profile and RoleManager</title>
		<link>http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/</link>
		<comments>http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 07:26:29 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/</guid>
		<description><![CDATA[A new ASP.NET MVC project includes preconfigured Membership, Profile and RoleManager providers right out of the box.&#160; Try it yourself – create a ASP.NET MVC application, crack open the web.config file and have a look.&#160; First, you’ll find the ApplicationServices database connection: &#60;connectionStrings&#62; &#160;&#160;&#60;add name=&#34;ApplicationServices&#34; &#160;&#160;&#160;&#160;&#160;&#160;&#160;connectionString=&#34;data source=.&#92;SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=&#124;DataDirectory&#124;aspnetdb.mdf;User Instance=true&#34; &#160;&#160;&#160;&#160;&#160;&#160;&#160;providerName=&#34;System.Data.SqlClient&#34;/&#62; &#60;/connectionStrings&#62; &#160; Notice the connection [...]]]></description>
			<content:encoded><![CDATA[<p>A new ASP.NET MVC project includes preconfigured Membership, Profile and RoleManager providers right out of the box.&#160; Try it yourself – create a ASP.NET MVC application, crack open the web.config file and have a look.&#160; </p>
<p>First, you’ll find the ApplicationServices database connection:    </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:417f66b0-c156-4264-b09d-f28075be06ad" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionString</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">data source=.&#92;SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true</span>&quot;<span style="color:#0000ff"> </span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">providerName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Data.SqlClient</span>&quot;<span style="color:#0000ff">/&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">connectionStrings</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>Notice the connection string is referencing the aspnetdb.mdf database hosted by SQL Express and it’s using integrated security so it’ll just work for you without having to call out a specific database login or anything. </p>
<p>Scroll down the file a bit and you’ll find each of the three noted sections:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5dda06dc-c123-40b9-a65b-cb0ff1c317dd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">membership</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff">/&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetSqlMembershipProvider</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">enablePasswordRetrieval</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">enablePasswordReset</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">true</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">requiresQuestionAndAnswer</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">requiresUniqueEmail</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">passwordFormat</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">Hashed</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">maxInvalidPasswordAttempts</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">5</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">minRequiredPasswordLength</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">6</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">minRequiredNonalphanumericCharacters</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">0</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">passwordAttemptWindow</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">10</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">passwordStrengthRegularExpression</span><span style="color:#0000ff">=</span>&quot;&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">membership</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">profile</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff">/&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetSqlProfileProvider</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff"></span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">/&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">profile</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">roleManager</span><span style="color:#0000ff"> </span><span style="color:#ff0000">enabled</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">false</span>&quot;<span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">clear</span><span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">connectionStringName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">ApplicationServices</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetSqlRoleProvider</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff">&lt;</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">applicationName</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">/</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">AspNetWindowsTokenRoleProvider</span>&quot;<span style="color:#0000ff"> </span><span style="color:#ff0000">type</span><span style="color:#0000ff">=</span>&quot;<span style="color:#0000ff">System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</span>&quot;<span style="color:#0000ff"> /&gt;</span></li>
<li style="background: #f3f3f3">&#160;&#160;<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">providers</span><span style="color:#0000ff">&gt;</span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">roleManager</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Really. It’s all there. Still don’t believe me.&#160; Run the application, walk through the registration process and finally login and logout.&#160; Completely functional – and you didn’t have to do a thing!</p>
<p>What else?&#160; Well, you can manage your users via the Configuration Manager which is hiding in Visual Studio behind Projects &gt; ASP.NET Configuration.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb.png" width="252" height="342" /></a> </p>
<p>The ASP.NET Web Site Administration Tool isn’t MVC-specific (neither is the Membership, Profile or RoleManager stuff) but it’s neat and I hardly ever see anyone using it.&#160; Here you can set up and edit users, roles, and set access permissions for your site. You can manage application settings, establish your SMTP settings, configure debugging and tracing, define default error page and even take your application offline.&#160; The UI is rather plain-Jane but it works great.</p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb1.png" width="779" height="452" /></a></p>
<p>And here’s the best of all.&#160; Let’s say you, like most of us, don’t want to run your application on top of the aspnetdb.mdf database.&#160; Let’s suppose you want to use your own database and you’d like to add the membership stuff to it.&#160; Well, that’s easy enough. Take a look inside your [drive:]\%windir%\Microsoft.Net\Framework\v2.0.50727\ folder.&#160; Here you’ll find a bunch of files.&#160; If you were to run the InstallCommon.sql, InstallMembership.sql, InstallRoles.sql and InstallProfile.sql files against the database of your choices, you’d be installing the same membership, profile and role artifacts which are found in the aspnet.db to your own database.&#160; </p>
<p>Too much trouble?&#160; Okay. Run [drive:]\%windir%\Microsoft.Net\Framework\v2.0.50727\aspnet_regsql.exe from the command line instead.&#160; This will launch the ASP.NET SQL Server Setup Wizard which walks you through the installation of those same database objects into the new or existing database of your choice. You may not always have the luxury of using this tool on your destination server, but you should use it whenever you can.&#160; </p>
<p><a href="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2010/01/image-thumb2.png" width="592" height="458" /></a> </p>
<p>Last tip: don’t forget to update the ApplicationServices connectionstring to point to your custom database after the setup is complete.</p>
<p>At the risk of sounding like a smarty, everything I’ve mentioned in this post has been around for quite a while. The thing is that not everyone has had the opportunity to use it.&#160; And it makes sense. I know I’ve worked on projects which used custom membership services.&#160; Why bother with the out-of-the-box stuff, right?&#160;&#160; And the .NET framework is so massive, who can know it all. Well, eventually you might have a chance to architect your own solution using any implementation you’d like or you will have the time to play around with another aspect of the framework.&#160; When you do, think back to this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2010/01/04/getting-started-with-aspnet-membership-profile-and-rolemanager/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>.NET MailMessage, LinkedResources, AlternateViews and Exceptions</title>
		<link>http://johnnycoder.com/blog/2009/04/15/net-mailmessage-linkedresources-alternateviews-and-exceptions/</link>
		<comments>http://johnnycoder.com/blog/2009/04/15/net-mailmessage-linkedresources-alternateviews-and-exceptions/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 05:05:34 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Library]]></category>
		<category><![CDATA[Samples]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2009/04/15/net-mailmessage-linkedresources-alternateviews-and-exceptions/</guid>
		<description><![CDATA[It doesn’t take much to hack together email functionality using the .NET framework.&#160; In most cases you can new-up a MailMessage reference, assign sender and recipient addresses, provide a subject and a message body, configure your SMTP settings and then send.&#160; Done and done. But let’s say you need to provide both plain text and [...]]]></description>
			<content:encoded><![CDATA[<p>It doesn’t take much to hack together email functionality using the .NET framework.&#160; In most cases you can new-up a MailMessage reference, assign sender and recipient addresses, provide a subject and a message body, configure your SMTP settings and then send.&#160; Done and done.</p>
<p>But let’s say you need to provide both plain text and HTML versions of your message body.&#160; Or maybe you would like to embed an image or two within the message body.&#160; Or, what if, for some reason, you actually want to handle exceptions appropriately.&#160; Well, there’s more to it then.</p>
<p>There are a numerous ways to better organize the following code.&#160; In fact, we just went through an exercise at work where we refactored the heck out of the core email functionality and produce a really clean usable component which can be easily mocked, configured and leverages email templates.&#160; It’s pretty cool.&#160; That being said, I believe the following sample demonstrates the aforementioned core features of .NET emailing.&#160; </p>
<p>I hope it helps. Let me know if I missed anything or it the example could be more clear.</p>
<pre class="code"><span style="color: blue">try
</span>{
    <span style="color: green">// Assign a sender, recipient and subject to new mail message
    </span><span style="color: #2b91af">MailAddress </span>sender =
        <span style="color: blue">new </span><span style="color: #2b91af">MailAddress</span>(<span style="color: #a31515">&quot;sender@johnnycoder.com&quot;</span>, <span style="color: #a31515">&quot;Sender&quot;</span>);

    <span style="color: #2b91af">MailAddress </span>recipient =
        <span style="color: blue">new </span><span style="color: #2b91af">MailAddress</span>(<span style="color: #a31515">&quot;recipient@johnnycoder.com&quot;</span>, <span style="color: #a31515">&quot;Recipient&quot;</span>);

    <span style="color: #2b91af">MailMessage </span>m = <span style="color: blue">new </span><span style="color: #2b91af">MailMessage</span>(sender, recipient);
    m.Subject = <span style="color: #a31515">&quot;Test Message&quot;</span>;

    <span style="color: green">// Define the plain text alternate view and add to message
    </span><span style="color: blue">string </span>plainTextBody =
        <span style="color: #a31515">&quot;You must use an email client that supports HTML messages&quot;</span>;

    <span style="color: #2b91af">AlternateView </span>plainTextView =
        <span style="color: #2b91af">AlternateView</span>.CreateAlternateViewFromString(
            plainTextBody, <span style="color: blue">null</span>, <span style="color: #2b91af">MediaTypeNames</span>.<span style="color: #2b91af">Text</span>.Plain);

    m.AlternateViews.Add(plainTextView);

    <span style="color: green">// Define the html alternate view with embedded image and
    // add to message. To reference images attached as linked
    // resources from your HTML message body, use &quot;cid:contentID&quot;
    // in the &lt;img&gt; tag...
    </span><span style="color: blue">string </span>htmlBody =
        <span style="color: #a31515">&quot;&lt;html&gt;&lt;body&gt;&lt;h1&gt;Picture&lt;/h1&gt;&lt;br&gt;&quot; </span>+
        <span style="color: #a31515">&quot;&lt;img src=\&quot;cid:SampleImage\&quot;&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span>;

    <span style="color: #2b91af">AlternateView </span>htmlView =
        <span style="color: #2b91af">AlternateView</span>.CreateAlternateViewFromString(
            htmlBody, <span style="color: blue">null</span>, <span style="color: #2b91af">MediaTypeNames</span>.<span style="color: #2b91af">Text</span>.Html);

    <span style="color: green">// ...and then define the actual LinkedResource matching the
    // ContentID property as found in the image tag. In this case,
    // the HTML message includes the tag
    // &lt;img src=\&quot;cid:SampleImage\&quot;&gt; and the following
    // LinkedResource.ContentId is set to &quot;SampleImage&quot;
    </span><span style="color: #2b91af">LinkedResource </span>sampleImage =
        <span style="color: blue">new </span><span style="color: #2b91af">LinkedResource</span>(<span style="color: #a31515">&quot;sample.jpg&quot;</span>,
            <span style="color: #2b91af">MediaTypeNames</span>.<span style="color: #2b91af">Image</span>.Jpeg);
    sampleImage.ContentId = <span style="color: #a31515">&quot;SampleImage&quot;</span>;

    htmlView.LinkedResources.Add(sampleImage);

    m.AlternateViews.Add(htmlView);

    <span style="color: green">// Finally, configure smtp or alternatively use the
    // system.net mailSettings
    </span><span style="color: #2b91af">SmtpClient </span>smtp = <span style="color: blue">new </span><span style="color: #2b91af">SmtpClient
          </span>{
              Host = <span style="color: #a31515">&quot;smtp.bigcompany.com&quot;</span>,
              UseDefaultCredentials = <span style="color: blue">false</span>,
              Credentials =
                  <span style="color: blue">new </span><span style="color: #2b91af">NetworkCredential</span>(<span style="color: #a31515">&quot;username&quot;</span>, <span style="color: #a31515">&quot;password&quot;</span>)
          };

    <span style="color: green">//&lt;system.net&gt;
    //    &lt;mailSettings&gt;
    //        &lt;smtp deliveryMethod=&quot;Network&quot;&gt;
    //            &lt;network host=&quot;smtp.bigcompany.com&quot;
    //              port=&quot;25&quot; defaultCredentials=&quot;true&quot;/&gt;
    //        &lt;/smtp&gt;
    //    &lt;/mailSettings&gt;
    //&lt;/system.net&gt;

    </span>smtp.Send(m);
}
<span style="color: blue">catch </span>(<span style="color: #2b91af">ArgumentException</span>)
{
    <span style="color: blue">throw new
        </span><span style="color: #2b91af">ArgumentException</span>(<span style="color: #a31515">&quot;Undefined sender and/or recipient.&quot;</span>);
}
<span style="color: blue">catch </span>(<span style="color: #2b91af">FormatException</span>)
{
    <span style="color: blue">throw new
        </span><span style="color: #2b91af">FormatException</span>(<span style="color: #a31515">&quot;Invalid sender and/or recipient.&quot;</span>);
}
<span style="color: blue">catch </span>(<span style="color: #2b91af">InvalidOperationException</span>)
{
    <span style="color: blue">throw new
        </span><span style="color: #2b91af">InvalidOperationException</span>(<span style="color: #a31515">&quot;Undefined SMTP server.&quot;</span>);
}
<span style="color: blue">catch </span>(<span style="color: #2b91af">SmtpFailedRecipientException</span>)
{
    <span style="color: blue">throw new </span><span style="color: #2b91af">SmtpFailedRecipientException</span>(
        <span style="color: #a31515">&quot;The mail server says that there is no mailbox for recipient&quot;</span>);
}
<span style="color: blue">catch </span>(<span style="color: #2b91af">SmtpException </span>ex)
{
    <span style="color: green">// Invalid hostnames result in a WebException InnerException that
    // provides a more descriptive error, so get the base exception
    </span><span style="color: #2b91af">Exception </span>inner = ex.GetBaseException();
    <span style="color: blue">throw new </span><span style="color: #2b91af">SmtpException</span>(<span style="color: #a31515">&quot;Could not send message: &quot; </span>+ inner.Message);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2009/04/15/net-mailmessage-linkedresources-alternateviews-and-exceptions/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>Migrating to IIS7</title>
		<link>http://johnnycoder.com/blog/2009/04/06/migrating-to-iis7/</link>
		<comments>http://johnnycoder.com/blog/2009/04/06/migrating-to-iis7/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 04:11:29 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2009/04/06/migrating-to-iis7/</guid>
		<description><![CDATA[It wasn’t until recently (December) that I started giving IIS7 any attention.&#160; I suspect its because I don’t have to do much inside of IIS when I’m developing .NET applications on my Vista Machine and I haven’t deployed to many Windows Server 2008 machines yet.&#160; Though there’s a impressive amount of information on the IIS [...]]]></description>
			<content:encoded><![CDATA[<p>It wasn’t until recently (December) that I started giving IIS7 any attention.&#160; I suspect its because I don’t have to do much inside of IIS when I’m developing .NET applications on my Vista Machine and I haven’t deployed to many Windows Server 2008 machines yet.&#160; Though there’s a impressive amount of information on the <a href="http://www.iis.net/" target="_blank">IIS Site</a> and I’ve read and heard numerous accounts of how easy it is to migrate to IIS7, my experiences haven’t been effortless.</p>
<p>I first wrestled with IIS7 when I attempted to get <a href="http://stackoverflow.com/questions/402034/subtext-and-iis-7s-integrated-pipeline-mode">SubText to run in Integrated Pipeline Mode</a>:</p>
<blockquote><p>Out of the box, SubText is unable to run under IIS7&#8242;s Integrated Pipeline Mode. Unfortunately, it goes beyond &quot;migrating&quot; the web.config to match the required format. For example, moving httpModules and httpHandlers to their new location within. As it turns out, Request is not available at Application_Start when running in Integrated mode and this causes SubText to fail too. </p>
<p>If we weren&#8217;t adding blog functionality to an existing, GoDaddy-hosted ASP.NET web site, we would be left with two options: Update the SubText codebase to not use the request context (plus fix whatever else surfaces) OR simply run SubText in classic mode. </p>
<p>Unfortunately, our current GoDaddy account is limiting as only a single app pool is available to us. Since the main site is configured for Integrated Pipeline Mode, we don&#8217;t have the freedom to change the IIS mode without impacting (read: breaking) the main site. </p>
<p>Short of switching to a more flexible host, the current plan is to modify the main site to run in classic mode. It&#8217;s a simple site and reverting the web.config to the classic mode format should not be a big deal. Alternatively, I&#8217;m toying with the idea of updating the SubText codebase to not use the request context at Application_Start. I haven&#8217;t heard on anyone running SubText in Integrated Mode and it might be a nice problem to solve &#8212; assuming there&#8217;s an end to the necessary updates.</p>
<p>Assuming there are about 8 more hours allocated to this effort, what&#8217;s the best approach? Am I missing any other options?</p>
</blockquote>
<p>Ultimately, we settled and opted to <a href="http://stackoverflow.com/questions/402034/subtext-and-iis-7s-integrated-pipeline-mode" target="_blank">run the Subtext in IIS7 but in Classic Mode</a>:</p>
<blockquote><p>As a follow up, we quickly commented out the Application_Start code which referenced the Request context. This experiment resulted in further exceptions. We&#8217;re currently moving forward with medications to the main site to run in classic mode.</p>
</blockquote>
<p>Since my IIS7 initiation, I’ve started to get the swing of things.&#160; Sure one needs to jump through a few hoops to get things running, but in retrospect it is all reasonable and once your get some of the basic steps down, it is pretty darn easy.&#160; Hence, I offer three simple tips:</p>
<p>1 &#8211; Pretty much everything in IIS7 is locked down by default.&#160; I’m pretty sure you can serve up an HTML page out of the box, but you need to enable even the most basic options like ASP.NET Services and Windows Authentication. Along those lines, here are two of the better articles I found on <a href="http://learn.iis.net/page.aspx/29/installing-iis7-on-windows-server-2008/" target="_blank">installing IIS7 on Windows Server 2008</a> and <a href="http://www.bloggingdeveloper.com/post/Creating-IIS7-sites-applications-and-virtual-directories-using-Internet-Information-Services-Manager.aspx" target="_blank">setting up IIS7 applications</a>.     </p>
<p>2 &#8211; Another big gotcha is related to configuration locking.&#160; Basically, you need to <a href="http://blog.donnfelker.com/post/IIS-7-This-configuration-section-cannot-be-used-at-this-path.aspx" target="_blank">unlock your web.config modules and handles sections</a> before they can be formatted per IIS7 compliance. Execute the following at the command prompt and you are good to go: </p>
<blockquote><p align="left">%systemroot%\system32\inetsrv\APPCMD.EXE unlock config -section:system.webServer/modules </p>
<p align="left">%systemroot%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers </p>
</blockquote>
<p>3 &#8211; Finally, let <a href="http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe/" target="_blank">AppCmd.exe</a> do your heavy lifting and make your web.config to IIS7 compliant by executing a like migration command: </p>
<blockquote><p align="left">%systemroot%\system32\inetsrv\APPCMD.EXE migrate config &quot;Default Web Site/Application&quot;      </p>
</blockquote>
<p>That’s it. Easy, right? By the way, if you are interested in learning more about IIS7, I highly recommend <a href="http://www.slickthought.net/" target="_blank">Jeff Brand’s</a>&#160;<a href="http://www.slickthought.net/post/2008/08/Spaghetti-Code-Podcast---IIS7-with-Robert-Boedigheimer.aspx">Spaghetti Code Podcast on IIS7 with Robert Boedigheimer</a> and I again suggest you check out the <a href="http://www.iis.net/" target="_blank">IIS Site</a>. </p>
<p></p>
<div class="wlWriterEditableSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:1e585d83-c3ab-4ba0-b1d8-afdeb906e849" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2009/04/06/migrating-to-iis7/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2009/04/06/migrating-to-iis7/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2009/04/06/migrating-to-iis7/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Caching with C#, AOP and PostSharp</title>
		<link>http://johnnycoder.com/blog/2009/01/16/caching-with-c-aop-and-postsharp/</link>
		<comments>http://johnnycoder.com/blog/2009/01/16/caching-with-c-aop-and-postsharp/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 01:53:57 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2009/01/16/caching-with-c-aop-and-postsharp/</guid>
		<description><![CDATA[I&#8217;ve been spending lots of time getting my head around Aspect-Oriented Programming (AOP). At its foundation, AOP separates crosscutting concerns (concerns which are not localizable and cannot be implemented successfully using pure imperative or object-oriented programming) into loosely coupled, modularized units called aspects and injects them into the otherwise one-dimensional base program.&#160; Without AOP, we [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending lots of time getting my head around <a href="http://en.wikipedia.org/wiki/Aspect-oriented_software_development">Aspect-Oriented Programming (AOP)</a>. At its foundation, AOP separates crosscutting concerns (concerns which are not localizable and cannot be implemented successfully using pure imperative or object-oriented programming) into loosely coupled, modularized units called aspects and injects them into the otherwise one-dimensional base program.&nbsp; Without AOP, we end up with a system with tangled and scattered code which is harder to design, understand, implement, and evolve primarily due to poor traceability, lower productively, less code reuse and testing difficulties. With AOP, well, my head started to hurt&#8230;until I put an ended to my research and put AOP to practice.<a href="http://johnnycoder.com/blog/wp-content/uploads/2009/01/image4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 20px; border-right-width: 0px" height="59" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2009/01/image-thumb4.png" width="244" align="right" border="0"></a></p>
<p>I know it&#8217;s a bit of a tease, but I&#8217;m going to save my &#8220;What is OAP&#8221; post for another day.&nbsp; Right now, I&#8217;m going to show you some code.</p>
<p><a href="http://www.postsharp.org/">Postsharp</a> is an open source library which encapsulate aspects as custom attributes and adds new behaviors to your code through policy injection (which is just another name for AOP.)&nbsp; </p>
<h3>Smelly, Old Code</h3>
<p>The follow code serves as an example of a crosscutting concern (Cache) which needs to be separated from the base program and modularized into an aspect.&nbsp; Notice the offending code checks the cache and queries the database.&nbsp; It laughs in the face of the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsibility Principle</a>. </p>
<p><a href="http://11011.net/software/vspaste"></a>
<pre class="code"><span style="color: blue">private const string </span>KeyNumber = <span style="color: #a31515">"RandomNumber"</span>;</pre>
<p><a href="http://11011.net/software/vspaste"></a>
<pre class="code"><span style="color: blue">private int </span>GetNumber()
{
    <span style="color: blue">int </span>value;
    <span style="color: blue">if </span>(!<span style="color: #2b91af">CacheHelper</span>.Get(KeyNumber, <span style="color: blue">out </span>value))
    {
        value = <span style="color: #2b91af">DataAccess</span>.GetNumberRandom();
        <span style="color: #2b91af">CacheHelper</span>.Add(value, KeyNumber);
    }

    <span style="color: blue">return </span>value;
}
</pre>
<h3>Shiny, Happy Code</h3>
<p>Using PostSharp, GetNumber() is left to do one thing (query the database) and all the caching checks are handled by the aspect, the custom CacheAttribute.&nbsp; Notice this is all hooked up by decorating GetNumber() with the CacheAttribute tag which accepts the key in the constructor.</p>
<pre class="code"><span style="color: blue">private const string </span>KeyNumber = <span style="color: #a31515">"RandomNumber"</span>;</pre>
<p><a href="http://11011.net/software/vspaste"></a>
<pre class="code"><span style="color: green">// Pass the key associated with the cached item in the constructor
</span>[<span style="color: #2b91af">Cache</span>(KeyNumber)]
<span style="color: blue">private int </span>GetNumber()
{
    <span style="color: green">// This logic is only executed if the CacheAttribute calls upon it.
    </span><span style="color: blue">return </span><span style="color: #2b91af">DataAccess</span>.GetNumberRandom();
}
</pre>
<p>The attribute&#8217;s logic is basic but very powerful.&nbsp; When the GetNumber (or any other method which is decorated with the CacheAttribute)&nbsp; is invoked, CacheAttribute checks to see if the data is in cache using the provided key.&nbsp; If so, the data is extracted and returned. Period. The GetNumber method is completely bypassed and never executed.&nbsp; In the sample application, I added some logging to help clarify this point.&nbsp; However, if the data is not found in cache, the custom attribute invokes the caller, the GetNumber() method, stores the result in cache and then returns the value.&nbsp; In this case, GetNumber&#8217;s logic is executed but it is invoke via the CacheAttribute.&nbsp; </p>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>PostSharp.Laos;

<span style="color: blue">namespace </span>PostSharpWebApplicationCache
{
    [<span style="color: #2b91af">Serializable</span>]
    <span style="color: blue">public sealed class </span><span style="color: #2b91af">CacheAttribute </span>: <span style="color: #2b91af">OnMethodInvocationAspect
    </span>{
        <span style="color: blue">private readonly string </span>key;

        <span style="color: blue">public </span>CacheAttribute(<span style="color: blue">string </span>key)
        {
            <span style="color: blue">this</span>.key = key;
        }

        <span style="color: blue">public override void </span>OnInvocation(<span style="color: #2b91af">MethodInvocationEventArgs </span>context)
        {
            <span style="color: blue">object </span>value;

            <span style="color: blue">if </span>(!<span style="color: #2b91af">CacheHelper</span>.Get(key, <span style="color: blue">out </span>value))
            {
                <span style="color: green">// Do lookup based on caller's logic.
                </span>value = context.Delegate.DynamicInvoke();
                <span style="color: #2b91af">CacheHelper</span>.Add(value, key);
            }

            context.ReturnValue = value;
        }
    }
}</pre>
<p>As you can see, both the smelly, old code and the shiny, happy code achieve the same effect, but the latter option is a lot cleaner and more elegant if you ask me. </p>
<p>As noted, I&#8217;ve included some downloaded code if you want to play around with Postsharp and AOP on your own.&nbsp; To get the code to work, you&#8217;ll need to visit the Postsharp site and install the latest bits.&nbsp; In my case, I&#8217;m using <a href="http://www.postsharp.org/all-downloads">PostSharp 1.0</a>.&nbsp; Please don&#8217;t be fooled.&nbsp; You&#8217;ll need to use an ASP.NET Web Application Project rather than ASP.NET Web Site in order for PostSharp to work.&nbsp; This is because <a href="http://www.postsharp.org/aop-net/compiletime-weaving">Postsharp does compile-time weaving and cleverly mucks with your IL</a>. Details.&nbsp; Don&#8217;t worry. we&#8217;ll get into all of it.&nbsp; For now, just trust me and know the sample project is a Web Application Project.&nbsp; Enjoy.</p>
<p>&nbsp;</p>
<p><div class="wlWriterSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:cfd03151-35d3-43e7-8514-5b92457308e1" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<div>Download Sample PostSharp Web Project: <a href="http://johnnycoder.com/blog/wp-content/uploads/2009/01/postsharpwebapplicationcache.zip" target="_blank">PostSharpWebApplicationCache.zip</a></div>
</p>
</div>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:00b2eb1d-aa20-416d-b5d8-48d6d0b7a945" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2009/01/16/caching-with-c-aop-and-postsharp/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2009/01/16/caching-with-c-aop-and-postsharp/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2009/01/16/caching-with-c-aop-and-postsharp/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>jTemplates with jQuery, AJAX and Json</title>
		<link>http://johnnycoder.com/blog/2008/12/18/jtemplates-with-jquery-ajax-and-json/</link>
		<comments>http://johnnycoder.com/blog/2008/12/18/jtemplates-with-jquery-ajax-and-json/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 04:22:17 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Json]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/12/18/jtemplates-with-jquery-ajax-and-json/</guid>
		<description><![CDATA[jTemplates is a jQuery plugin and template engine for Javascript.&#160; If you keep up with Dave Ward and/or Rick Strahl you may already be familiar with jTemplates as they have both highlighted the plugin on their respective bolgs.&#160; About 1.5 months ago, however, I got into the action and started using jTemplates in conjunction with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jtemplates.tpython.com/">jTemplates</a> is a jQuery plugin and template engine for Javascript.&nbsp; If you keep up with <a href="http://encosia.com/">Dave Ward</a> and/or <a href="http://www.west-wind.com/Weblog">Rick Strahl</a> you may already be familiar with jTemplates as they have both highlighted the plugin on their respective bolgs.&nbsp; About 1.5 months ago, however, I got into the action and started using jTemplates in conjunction with jQuery, AJAX and Json to dynamically populate dropdowns and tables on the client side. </p>
<p>As you&#8217;ll see in the examples, jTemplates provides custom syntax to do such things as iterate through Json data and populate a predefined template.&nbsp; Once you get a grasp of the syntax and the proper usage, you will be ready to roll.&nbsp; Getting started is easy &#8212; just download the latest <a href="http://code.google.com/p/jqueryjs/">jQuery</a> and <a href="http://jtemplates.tpython.com/">jTemplate</a> bits and reference them within your html or aspx file. </p>
<p>Next, you need to define and host your templates.&nbsp; In the included sample project, I&#8217;ve defined two templates to aid in the population of my dropdown and my table respectively.&nbsp; Here you will notice the dropdown template merely adds a singe &#8220;Select One&#8221; entry and then iterates over all project results adding a new option for each:</p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: green">-- Project Dropdown Template --</span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">="text/html" </span><span style="color: red">id</span><span style="color: blue">="TemplateProjectSelect"&gt;
</span>&lt;option value=""&gt;Select One&lt;/option&gt;
{#foreach $T.result as project}
    &lt;option value="{$T.project.id}"&gt;{$T.project.name}&lt;/option&gt;
{#/for}
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And the following table template is a little more complex but still very to interpret.&nbsp; Here, we are iterating over each task row and appending a new row to the table for each.&nbsp; Notice there&#8217;s a MAIN template and a ROW template.&nbsp; The MAIN template passes along the current record to the ROW template.&nbsp; The ROW template sets the appropriate class (think table zebra stripes) and column values based on the current &#8220;cycle.&#8221;</p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: green">-- Results Table Template --</span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">="text/html" </span><span style="color: red">id</span><span style="color: blue">="TemplateResultsTable"&gt;
</span>{#template MAIN}
&lt;table width="500" border="0" cellpadding="5" cellspacing="0"&gt;
  &lt;tr&gt;
    &lt;th width="50"&gt;ID&lt;/th&gt;
    &lt;th width="300"&gt;Task&lt;/th&gt;
    &lt;th width="104"&gt;Hours&lt;/th&gt;
  &lt;/tr&gt;
  {#foreach $T.result as task}
    {#include ROW root=$T.task}
  {#/for}
&lt;/table&gt;
{#/template MAIN}

{#template ROW}
&lt;tr class="{#cycle values=['','evenRow']}"&gt;
  &lt;td&gt;{$T.id}&lt;/td&gt;
  &lt;td&gt;{$T.name}&lt;/td&gt;
  &lt;td&gt;{$T.hours}&lt;/td&gt;
&lt;/tr&gt;
{#/template ROW}
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>How&#8217;s about hosting the templates?&nbsp; You have a few options.&nbsp; First, you could save the templates off in their own file.&nbsp; This is <a href="http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/">the approach Dave Ward took in his article</a>. Though this approach is clean, it doesn&#8217;t perform all that well.&nbsp; The preferred approach is to &#8220;embed&#8221; your templates within the html/aspx file by wrapping each of the above templates with a script tag like so:</p>
<p><span style="color: blue"></span></p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">="text/html" </span><span style="color: red">id</span><span style="color: blue">="TemplateResultsTable"&gt; 

</span>... template here ...

<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt; </span></pre>
<p>As <a href="http://www.west-wind.com/Weblog/posts/509108.aspx">shared on Rick Strahl&#8217;s post</a>, this is the preferred approach as using &lt;script type=”text/html”&gt; that allows hiding any markup in the document without interfering with HTML validators. The script can be accessed by its ID and the content retrieved using the jQuery .html() syntax.</p>
<p>Once your template is in place, you simply need to assign your template to your container (a div) and then process the template using your Json data.&nbsp; As noted above, you may reference an external template using the following:</p>
<pre class="code">$(<span style="color: #a31515">'#tasks'</span>).setTemplate(<span style="color: #a31515">'Template.htm'</span>);</pre>
<p><a href="http://11011.net/software/vspaste"></a>Or you may select the template from the html/aspx itself:</p>
<pre class="code">$(<span style="color: #a31515">'#tasks'</span>).setTemplate($(<span style="color: #a31515">"#TemplateResultsTable"</span>).html());</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Again, the preferred approach is the latter.&nbsp; In either case, you process the template data (results) as follows:</p>
<pre class="code">$(<span style="color: #a31515">'#tasks'</span>).processTemplate(results);</pre>
<p><a href="http://11011.net/software/vspaste"></a>
<pre class="code"><span style="color: blue"></span></pre>
<p>A quick note on .processTemplate.&nbsp; You don&#8217;t actually have to provide any data.&nbsp; You can send null into the processTemplate method if, for example, no processing is required.&nbsp; In the downloadable example, I create a static template which acts as a place holder when my page first loads and no table data is available. Here&#8217;s the sample template and javascript:</p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: green">-- Emtpy Table Template --</span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">="text/html" </span><span style="color: red">id</span><span style="color: blue">="TemplateResultsEmpty"&gt;
</span>Select a client and project...
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a>
<pre class="code">$(<span style="color: #a31515">'#tasks'</span>).setTemplate($(<span style="color: #a31515">"#TemplateResultsEmpty"</span>).html());
$(<span style="color: #a31515">'#tasks'</span>).processTemplate(<span style="color: blue">null</span>);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Before I wrap things up, I should mention the downloadable sample project doesn&#8217;t only show off jTemplates.&nbsp; It also demonstrates how to use jQuery and an &#8220;parameterized&#8221; HTTPHandler to pull back Json data which is somewhat an extension of <a href="http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/">my earlier HTTPHandler post</a>.</p>
</p>
<div class="wlWriterSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:6a5b99e2-f002-4bf1-86f5-f79ddb7cf63b" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<div>Download jTemplates Sample Project: <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/12/jtemplates.zip" target="_blank">jTemplates.zip</a></div>
</p>
</div>
<p>&nbsp;</p>
</p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:a6aa7101-097f-4c86-bb3c-9a91e2bc6568" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/12/18/jtemplates-with-jquery-ajax-and-json/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/12/18/jtemplates-with-jquery-ajax-and-json/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/12/18/jtemplates-with-jquery-ajax-and-json/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>HTTPHandler with JSON Data</title>
		<link>http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/</link>
		<comments>http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 17:24:17 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/</guid>
		<description><![CDATA[As javascript libraries, particularly jQuery, increase in popularity so do web techniques using AJAX and JSON. Have you ever seen this code?&#160; It is front and back of an ASPX file with the single responsibility to return JSON data per an AJAX request. GetDataPage.aspx &#60;%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetDataPage.aspx.cs" Inherits="GetDataPage" %&#62; &#60;%-- This minimal code [...]]]></description>
			<content:encoded><![CDATA[<p>As javascript libraries, particularly jQuery, increase in popularity so do web techniques using AJAX and JSON.</p>
<p>Have you ever seen this code?&nbsp; It is front and back of an ASPX file with the single responsibility to return JSON data per an AJAX request.</p>
<p><span style="text-decoration: underline">GetDataPage.aspx</span></p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Page </span><span style="color: red">Language</span><span style="color: blue">="C#" </span><span style="color: red">AutoEventWireup</span><span style="color: blue">="true"
    </span><span style="color: red">CodeFile</span><span style="color: blue">="GetDataPage.aspx.cs" </span><span style="color: red">Inherits</span><span style="color: blue">="GetDataPage" </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: green">--
    This minimal code is here to prevent the following error:
     "Using themed css files requires a header control on the page"
     Please see http://www.west-wind.com/WebLog/posts/4662.aspx
     for more information --</span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">head </span><span style="color: red">id</span><span style="color: blue">="Head1" </span><span style="color: red">runat</span><span style="color: blue">="server" </span><span style="color: red">visible</span><span style="color: blue">="false" /&gt;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><span style="text-decoration: underline">GetDataPage.aspx.cs</span></p>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Web;
<span style="color: blue">using </span>System.Text;

<span style="color: blue">public partial class </span><span style="color: #2b91af">GetDataPage </span>: System.Web.UI.<span style="color: #2b91af">Page
</span>{
    <span style="color: blue">protected void </span>Page_Load(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
    {
        <span style="color: green">// Clear out the buffer
        </span>Response.ClearHeaders();
        Response.ClearContent();
        Response.Clear();

        <span style="color: green">// Do not cache response
        </span>Response.Cache.SetCacheability(<span style="color: #2b91af">HttpCacheability</span>.NoCache);

        <span style="color: green">// Set the content type and encoding for JSON
        </span>Response.ContentType = <span style="color: #a31515">"application/json"</span>;
        Response.ContentEncoding = <span style="color: #2b91af">Encoding</span>.UTF8;

        <span style="color: blue">int </span>page = <span style="color: blue">int</span>.Parse(Request[<span style="color: #a31515">"p"</span>]);
        <span style="color: blue">string </span>results = <span style="color: #2b91af">DataAccess</span>.GetResults(page);

        Response.Write(results);

        <span style="color: green">// Flush the response buffer
        </span>Response.Flush();

        <span style="color: green">// Complete the request.  NOTE: Do not use Response.End() here,
        // because it throws a ThreadAbortException, which cannot be caught!
        </span><span style="color: #2b91af">HttpContext</span>.Current.ApplicationInstance.CompleteRequest();
    }
}
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>You may have noticed there&#8217;s a comment for nearly every code block.&nbsp; At first, one may find the comments redundant and unnecessary, but really they are call for help.&nbsp; A code:comment ratio like this usually indicates you really need to focus on what&#8217;s happening with the code because if you aren&#8217;t paying attention, bad things might happen.</p>
<p>As you have undoubtedly concluded, there&#8217;s a lot of overhead associated with returning JSON data from an ASPX file.&nbsp; This statement is especially true if you consider the alternative, an HTTPHandler.&nbsp; Here&#8217;s a cleaner, best-practices approach which provides the same outcome with less code, comments and risk.</p>
<p><span style="text-decoration: underline">GetDataHandler.ashx</span></p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">WebHandler </span><span style="color: red">Language</span><span style="color: blue">="C#" </span><span style="color: red">Class</span><span style="color: blue">="GetDataHandler" </span><span style="background: #ffee62">%&gt;

</span><span style="color: blue">using </span>System.Text;
<span style="color: blue">using </span>System.Web;

<span style="color: blue">public class </span><span style="color: #2b91af">GetDataHandler </span>: <span style="color: #2b91af">IHttpHandler
</span>{
    <span style="color: blue">public bool </span>IsReusable
    {
        <span style="color: blue">get </span>{ <span style="color: blue">return false</span>; }
    }

    <span style="color: blue">public void </span>ProcessRequest (<span style="color: #2b91af">HttpContext </span>context)
    {
        context.Response.ContentType = <span style="color: #a31515">"application/json"</span>;
        context.Response.ContentEncoding = <span style="color: #2b91af">Encoding</span>.UTF8;

        <span style="color: blue">int </span>page = <span style="color: blue">int</span>.Parse(context.Request[<span style="color: #a31515">"p"</span>]);
        <span style="color: blue">string </span>results = <span style="color: #2b91af">DataAccess</span>.GetResults(page);

        context.Response.Write(results);
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>If you are already accustomed to using generic handlers to stream back images, XML, JSON data, etc, this post was probably a bore. But it&#8217;s sometimes easy to forget what&#8217;s available to <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/12/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="160" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2008/12/image-thumb2.png" width="244" align="right" border="0"></a>you in the vast .NET stack, so hopefully you appreciate the friendly reminder.&nbsp; In either case, it still surprises me how many examples use the ASPX approach.&nbsp; In fact, the practice is common enough that I sometimes wonder if there&#8217;s an HTTPHandler gotcha to which I&#8217;m not privy .&nbsp; If I am missing something, please let me know.</p>
<p>If you&#8217;re still interested, attached you&#8217;ll find code which populates two jQuery Flexbox controls using JSON data provided through an ASPX and ASHX files.&nbsp; This may be worthwhile download if you&#8217;re interest in the generic handler code or you want a further look at Flexbox in action after <a href="http://johnnycoder.com/blog/2008/12/13/flexbox-jquery-plugin/">last week&#8217;s post</a>.</p>
<div class="wlWriterSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:c1d080fd-bc5d-4b7d-8d47-abe9f5cfbce0" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<div>Download JsonHandler Sample Project: <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/12/jsonhandler1.zip" target="_blank">JsonHandler.zip</a></div>
</p>
</div>
</p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:36b47f1d-cc23-4bfb-aa40-0ace90b1e1c5" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/12/16/httphandler-json-data/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>ASP.NET Charting Control</title>
		<link>http://johnnycoder.com/blog/2008/12/11/aspnet-charting-control/</link>
		<comments>http://johnnycoder.com/blog/2008/12/11/aspnet-charting-control/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 17:57:40 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Controls]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/12/11/aspnet-charting-control/</guid>
		<description><![CDATA[Scott Guthrie recently posted about a cool new ASP.NET server control that can be used for free with ASP.NET 3.5 to enable rich browser-based charting scenarios. If you had a look at the ASP.NET Charting Control offering, you may have noticed how obnoxiously similar the charts and sample project looks compared to that provided by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx">Scott Guthrie</a> recently posted about a cool new ASP.NET server control that can be used for free with ASP.NET 3.5 <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/12/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="179" alt="image" src="http://johnnycoder.com/blog/wp-content/uploads/2008/12/image-thumb.png" width="244" align="right" border="0"></a>to enable rich browser-based charting scenarios. If you had a look at the ASP.NET Charting Control offering, you may have noticed how obnoxiously similar the charts and sample project looks compared to that provided by <a href="http://www.dundas.com/Products/Chart/NET/Index.aspx">Dundas Chart</a>.&nbsp; Well, <a href="http://blogs.msdn.com/alexgor/archive/2008/11/07/microsoft-chart-control-vs-dundas-chart-control.aspx">there’s good reason</a>:<br />
<blockquote>
<p>Microsoft acquired Dundas Data Visualization Intellectual Property in April 2007 and is integrating this technology in different Microsoft products. New Chart and Gauge report items were already released as part of SQL Reporting Services 2008. We also announced the new Map report item which will be available in the next release of SSRS. Microsoft Chart controls (ASP.NET and Windows Forms), released at PDC 2008, also based on the source code acquired from Dundas! Microsoft Chart control is available as a separate installation for .NET Framework 3.5 SP1 and will be part of .NET Framework 4.0. </p>
</blockquote>
<p>I’ve used Dundas products for quite some time and they have been very solid.&nbsp; The only place the product falls down is when one wishes to include Dundas charts as high-quality, printable images embedded within a PDF, for example. If you are interested in knowing more about the printing limitations, I can dig up some of the why-my-reports-look-great-online-but-look-like-crap-on-paper documentation I’ve compiled over the years.
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c&amp;DisplayLang=en">Download the free Microsoft Chart Controls</a>
<li><a href="http://www.microsoft.com/downloads/details.aspx?familyid=1D69CE13-E1E5-4315-825C-F14D33A303E9&amp;displaylang=en">Download the VS 2008 Tool Support for the Chart Controls</a>
<li><a href="http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591">Download the Microsoft Chart Controls Samples</a>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EE8F6F35-B087-4324-9DBA-6DD5E844FD9F&amp;displaylang=en">Download the Microsoft Chart Controls Documentation</a>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/threads/">Visit the Microsoft Chart Control Forum</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/12/11/aspnet-charting-control/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Export GridView to Excel within an UpdatePanel</title>
		<link>http://johnnycoder.com/blog/2008/07/25/export-gridview-to-excel-within-an-updatepanel/</link>
		<comments>http://johnnycoder.com/blog/2008/07/25/export-gridview-to-excel-within-an-updatepanel/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 02:15:51 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gridview]]></category>
		<category><![CDATA[Samples]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/07/25/export-gridview-to-excel-within-an-updatepanel/</guid>
		<description><![CDATA[There&#8217;s a ton of information online about exporting a DataGrid or GridView to Excel, but most variations do not consider the GridView may reside within an UpdatePanel.  It goes without saying, but I was disappointed when I recently dusted off my &#8220;Export GridView to Excel&#8221; code snippet and encountered a number of exceptions.  So I [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a ton of information online about exporting a DataGrid or GridView to Excel, but most variations do not consider the GridView may reside within an UpdatePanel.  It goes without saying, but I was disappointed when I recently dusted off my &#8220;Export GridView to Excel&#8221; code snippet and encountered a number of exceptions.  So I revisited a number of links and I collected a working solution.  If you need a &#8220;simple&#8221; way to export your GridView to Excel and you are using an UpdatePanel, I hope the following code finds you well:</p>
<pre class="code"><span style="color: #0000ff;">protected void </span>btnExport_Click(<span style="color: #0000ff;">object </span>sender, <span style="color: #2b91af;">EventArgs </span>e)
{
    <span style="color: #008000;">// Reference your own GridView here
    </span><span style="color: #0000ff;">if </span>(AccountGrid.Rows.Count &gt; 65535)
    {
        DisplayError(<span style="color: #a31515;">"Export to Excel is not allowed" </span>+
            <span style="color: #a31515;">"due to excessive number of rows."</span>);
        <span style="color: #0000ff;">return</span>;
    }

    <span style="color: #0000ff;">string </span>filename = <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">"Results_{0}_{1}.xls"</span>,
        <span style="color: #2b91af;">DateTime</span>.Today.Month.ToString(), <span style="color: #2b91af;">DateTime</span>.Today.Year.ToString());

    Response.Clear();
    Response.AddHeader(<span style="color: #a31515;">"Content-Disposition"</span>, <span style="color: #a31515;">"attachment;filename=" </span>+ filename);
    Response.Charset = <span style="color: #a31515;">""</span>;

    <span style="color: #008000;">// SetCacheability doesn't seem to make a difference (see update)
    </span>Response.Cache.SetCacheability(System.Web.<span style="color: #2b91af;">HttpCacheability</span>.NoCache);  

    Response.ContentType = <span style="color: #a31515;">"application/vnd.xls"</span>;

    System.IO.<span style="color: #2b91af;">StringWriter </span>stringWriter = <span style="color: #0000ff;">new </span>System.IO.<span style="color: #2b91af;">StringWriter</span>();
    System.Web.UI.<span style="color: #2b91af;">HtmlTextWriter </span>htmlWriter = <span style="color: #0000ff;">new </span><span style="color: #2b91af;">HtmlTextWriter</span>(stringWriter);

    <span style="color: #008000;">// Replace all gridview controls with literals
    </span>ClearControls(AccountGrid);

    <span style="color: #008000;">// Throws exception: Control 'ComputerGrid' of type 'GridView'
    // must be placed inside a form tag with runat=server.
    // ComputerGrid.RenderControl(htmlWrite);

    // Alternate to ComputerGrid.RenderControl above
    </span>System.Web.UI.HtmlControls.<span style="color: #2b91af;">HtmlForm </span>form
        = <span style="color: #0000ff;">new </span>System.Web.UI.HtmlControls.<span style="color: #2b91af;">HtmlForm</span>();
    Controls.Add(form);
    form.Controls.Add(AccountGrid);
    form.RenderControl(htmlWriter);

    Response.Write(stringWriter.ToString());
    Response.End();
}

<span style="color: #0000ff;">private void </span>ClearControls(<span style="color: #2b91af;">Control </span>control)
{
    <span style="color: #0000ff;">for </span>(<span style="color: #0000ff;">int </span>i = control.Controls.Count - 1; i &gt;= 0; i--)
    {
        ClearControls(control.Controls[i]);
    }

    <span style="color: #0000ff;">if </span>(!(control <span style="color: #0000ff;">is </span><span style="color: #2b91af;">TableCell</span>))
    {
        <span style="color: #0000ff;">if </span>(control.GetType().GetProperty(<span style="color: #a31515;">"SelectedItem"</span>) != <span style="color: #0000ff;">null</span>)
        {
            <span style="color: #2b91af;">LiteralControl </span>literal = <span style="color: #0000ff;">new </span><span style="color: #2b91af;">LiteralControl</span>();
            control.Parent.Controls.Add(literal);
            <span style="color: #0000ff;">try
            </span>{
                literal.Text =
                    (<span style="color: #0000ff;">string</span>)control.GetType().GetProperty(<span style="color: #a31515;">"SelectedItem"</span>).
                        GetValue(control, <span style="color: #0000ff;">null</span>);
            }
            <span style="color: #0000ff;">catch
            </span>{}
            control.Parent.Controls.Remove(control);
        }
        <span style="color: #0000ff;">else if </span>(control.GetType().GetProperty(<span style="color: #a31515;">"Text"</span>) != <span style="color: #0000ff;">null</span>)
        {
            <span style="color: #2b91af;">LiteralControl </span>literal = <span style="color: #0000ff;">new </span><span style="color: #2b91af;">LiteralControl</span>();
            control.Parent.Controls.Add(literal);
            literal.Text =
                (<span style="color: #0000ff;">string</span>)control.GetType().GetProperty(<span style="color: #a31515;">"Text"</span>).
                    GetValue(control, <span style="color: #0000ff;">null</span>);
            control.Parent.Controls.Remove(control);
        }
    }
    <span style="color: #0000ff;">return</span>;
}</pre>
<pre class="code"> </pre>
<h3>Update: 7/30/2008</h3>
<p>I previously noted that SetCacheability doesn&#8217;t seem to make a difference.  Well, I was right&#8230;until I deployed my code to a site behind SSL.  As it turns out, in order for Internet Explorer to open documents in Office (or any out-of-process, ActiveX document server), Internet Explorer must save the file to the local cache directory and ask the associated application to load the file by using IPersistFile::Load.</p>
<p><a href="http://support.microsoft.com/default.aspx?scid=KB;EN-US;q316431&amp;">http://support.microsoft.com/default.aspx?scid=KB;EN-US;q316431&amp;</a></p>
<p>If the file is not stored to disk, this operation fails. When Internet Explorer communicates with a secure Web site through SSL, Internet Explorer enforces any no-cache request. If the header or headers are present, Internet Explorer does not cache the file. Consequently, Office cannot open the file.</p>
<p>RESOLUTION: Web sites that want to allow this type of operation should remove the no-cache header or headers. In other words, comment out the following line of code particularly if you are running under SSL:</p>
<p>Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); </p>
<p> </p>
<h3>Additional Comments</h3>
<p>Per <a href="http://jinath.wordpress.com/2008/02/18/export-gridview-to-excel-inside-an-update-panel/">Jinath Blog</a>, if you are using an UpdatePanel, you may get a System.WebForms.PageRequestManagerParserErrorException exception.  The solution is to add a PostBackTrigger and give it’s ControlID as the excel export button’s ID or you can move your excel export button out side of the update panel.  I verified both options and they work great.  I ultimately went with the former option as such:</p>
<pre class="code">    ...
    <span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ContentTemplate</span><span style="color: #0000ff;">&gt;
    &lt;</span><span style="color: #a31515;">Triggers</span><span style="color: #0000ff;">&gt;
        &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">PostBackTrigger </span><span style="color: #ff0000;">ControlID</span><span style="color: #0000ff;">="btnExport" /&gt;
    &lt;/</span><span style="color: #a31515;">Triggers</span><span style="color: #0000ff;">&gt;
&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">UpdatePanel</span><span style="color: #0000ff;">&gt;
</span>...</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>Per <a href="http://aspalliance.com/771_CodeSnip_Exporting_GridView_to_Excel">ASPAlliance</a>, you may encounter issues a number of issues which require the following solution.  Check out the link (and the comments) for more details if you get stuck.  I only encountered #1 on the list.</p>
<ol>
<li>You may get an exception which states your Control &#8216;Grid&#8217; of type &#8216;GridView&#8217; must be placed inside a form tag with runat=server.  I overcame this by dynamically adding a form to the page and then the GridView to the form before RenderContent().  This solution came per the aforementioned post&#8217;s comments.</li>
<li>You may need to included the following page directive: EnableEventValidation=&#8221;false&#8221;.  I didn&#8217;t need to include this directive.</li>
<li>You may need Override the VerifyRenderingInServerForm Method.  I didn&#8217;t need to do so because I added my GridView control to a &#8220;mocked&#8221; form.<br />
 </li>
</ol>
<p>Per <a href="http://www.c-sharpcorner.com/UploadFile/DipalChoksi/ExportASPNetDataGridToExcel11222005041447AM/ExportASPNetDataGridToExcel.aspx">Dipal Choksi</a>, one can format the spreadsheet results in a generic manner by replacing all controls within the GridView with Literals.  This is reflected in the ClearControls() method above.  My prior implementation merely cleaned up the links associated with the sort functionality tied to the sortable headers.  This solution tackles all cells.</p>
<p>Additional Reference: <a href="http://gridviewguy.com/ArticleDetails.aspx?articleID=26">GridViewGuy</a> </p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:00b54b2d-1096-495d-bdd6-aac1a8f61396" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/07/25/export-gridview-to-excel-within-an-updatepanel/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/07/25/export-gridview-to-excel-within-an-updatepanel/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/07/25/export-gridview-to-excel-within-an-updatepanel/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
		<item>
		<title>Using .NET 3.5 Client Profile (BETA)</title>
		<link>http://johnnycoder.com/blog/2008/07/09/using-net-35-client-profile-beta/</link>
		<comments>http://johnnycoder.com/blog/2008/07/09/using-net-35-client-profile-beta/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 17:47:23 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Installers]]></category>
		<category><![CDATA[Services]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/07/09/using-net-35-client-profile-beta/</guid>
		<description><![CDATA[I am releasing/distributing a Windows application and service in a couple weeks.  Both application use the .NET 3.5 Framework and are wrapped up in a custom installer.  Rather than having my installer prompt the user to download the .NET 3.5 framework installer, I&#8217;m packaging it up with my setup program.  Very simply, I check to [...]]]></description>
			<content:encoded><![CDATA[<p>I am releasing/distributing a Windows application and service in a couple weeks.  Both application use the .NET 3.5 Framework and are wrapped up in a custom installer.  Rather than having my installer prompt the user to download the .NET 3.5 framework installer, I&#8217;m packaging it up with my setup program.  Very simply, I check to see if the framework is installed and then I silently expand and install .NET 3.5 if applicable.  Currently I am using the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=333325FD-AE52-4E35-B531-508D977D32A6&amp;displaylang=en">&#8220;online&#8221; version of the .NET 3.5 Framework installer</a> which weighs in at 2.7 MB. The arguably unnecessary file* completely bloats my setup package but the total size is, in my opinion, within reason.</p>
<p>You may have noticed that .NET Framework installs have gotten unacceptably large since the 1.0 days:</p>
<ul>
<li>.NET Framework 1.0 Redist: 19.7MB</li>
<li>.NET Framework 1.1 Redist: 23.1MB</li>
<li>.NET Framework 2.0 Redist: 22.4MB</li>
<li>.NET Framework 3.0 Redist: 50.3MB ( x86 )</li>
<li>.NET Framework 3.0 Redist: 90.1MB ( x64 )</li>
<li>.NET Framework 3.5 Redist: 197.0MB</li>
</ul>
<p>With consideration for the distribution size of the .NET 3.* releases, I should be thankful for the &#8220;online&#8221; version, but I&#8217;m not.  The &#8220;online&#8221; version is still too big especially if you know the ultra-slim <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4f7ae6fe-f4d1-4196-a372-80eab6d56332&amp;displaylang=en">Microsoft .NET Framework 3.5 Client Profile (BETA)</a> weighs in at a mere 217 KB by containing only a subset of features (Common Language Runtime, ClickOnce, Windows Forms, Windows Presentation Foundation and Windows Communication Foundation) found in the full installation of the .NET Framework. <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/07/image3.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px 10px 10px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/07/image-thumb3.png" border="0" alt="image" width="313" height="99" align="right" /></a></p>
<p>To add to my turmoil, I already know that both of my applications can use the bootstrapper as confirmed by selecting the &#8220;Client-only Framework subset&#8221; option within my project properties followed by a rebuild without warnings.</p>
<p>But, alas, the Client Profile installer is still in BETA with no published final release date other than &#8220;this summer.&#8221;  The fact that it is still in BETA isn&#8217;t a deal breaker, but the BETA version does put the end user in a less-than-optimal place when it comes to managing future .NET Framework installs.  Per the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=4f7ae6fe-f4d1-4196-a372-80eab6d56332&amp;displaylang=en">documentation</a>:</p>
<blockquote><p>The Microsoft .NET Framework 3.5 SP1 Client (BETA) cannot be upgraded to the full .NET Framework. Users will need to uninstall the .NET Framework 3.5 SP1 Client (BETA) before installing .NET Framework 3.5 SP1. This will be corrected with the final release of .NET Framework 3.5 SP1.</p></blockquote>
<p>That last sentence haunts me&#8230;.</p>
<p>Maybe I&#8217;m being overly sensitive but I don&#8217;t want my users having to uninstall .NET if they choose/need to upgrade the .NET framework.  After all, the primary reason I am packaging up the .NET installer in the first place is for the sake of user convenience (and I suspect the majority of user&#8217;s aren&#8217;t all the tech-savvy.) </p>
<p>I am left weighing my options.  I can either stick with the sub par &#8220;Online&#8221; version of the installer and cause .NET Framework upgrade grief for my user&#8217;s going forward OR I can improve the install experience of my product by distributing the Client Profile installer thus causing possible future inconvenience.  Right now, I am leaning towards the former option, but I could be steered otherwise &#8212; especially if the final version of the Client Profile installer were released, let&#8217;s say, this afternoon. </p>
<p>I&#8217;m torn. What would you do? </p>
<p>* Side note: I would love to exclude the .NET installer and only download it to the client&#8217;s machine and install if needed, but I feel my current approach is reasonable for now. That being said, I&#8217;m sure I will be messing around with this alternative option soon.  I&#8217;m currently using <a href="http://www.jrsoftware.org/isinfo.php">Inno Setup</a> which can seemly do anything so there&#8217;s hope.</p>
<p>References:</p>
<ol>
<li><a href="http://blog.deploymentengineering.com/2007/12/net-framework-size.html">.NET Framework Size</a> &#8211; Christopher Painter</li>
<li><a href="http://www.west-wind.com/WebLog/posts/292203.aspx">.NET 3.5 Framework Distribution Size</a> &#8211; Rick Strahl</li>
<li><a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx">Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta</a> &#8211; Scott Guthrie</li>
</ol>
<p> </p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:2ea70573-45a2-4105-b71d-15ca361e3aa3" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/07/09/using-net-35-client-profile-beta/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/07/09/using-net-35-client-profile-beta/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/07/09/using-net-35-client-profile-beta/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>LinkButton Image</title>
		<link>http://johnnycoder.com/blog/2008/07/02/linkbutton-image/</link>
		<comments>http://johnnycoder.com/blog/2008/07/02/linkbutton-image/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 06:08:49 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Gridview]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/07/02/linkbutton-image/</guid>
		<description><![CDATA[I am not a CSS expert, but the following technique can be used to easily apply an image next to virtually any link.  First you need to define your CSS class which sets the background to a referenced image.  .icon-cancel { background: url(../images/icons/cancel.gif) no-repeat left top; display:inline; padding-left:18px; margin-left: 10px; padding-right:10px; } Once defined, assign [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a CSS expert, but the following technique can be used to easily apply an image next to virtually any link. </p>
<p>First you need to define your CSS class which sets the background to a referenced image. </p>
<pre class="code"><span style="color: #a31515;">.icon-cancel </span>{
    <span style="color: #ff0000;">background</span>: <span style="color: #0000ff;">url(../images/icons/cancel.gif) no-repeat left top</span>;
    <span style="color: #ff0000;">display</span>:<span style="color: #0000ff;">inline</span>;
    <span style="color: #ff0000;">padding-left</span>:<span style="color: #0000ff;">18px</span>;
    <span style="color: #ff0000;">margin-left</span>: <span style="color: #0000ff;">10px</span>;
    <span style="color: #ff0000;">padding-right</span>:<span style="color: #0000ff;">10px</span>;
}</pre>
<p>Once defined, assign the class to your hyperlink.</p>
<pre class="code"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">="#" </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="icon-cancel"&gt;</span>Cancel<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: #0000ff;">&gt;</span></pre>
<pre class="code"> </pre>
<p><span style="font-family: Trebuchet MS;">You may need to play with padding and margin, but you will end up with something similar to the following result:</span></p>
<pre class="code"><a href="http://johnnycoder.com/blog/wp-content/uploads/2008/07/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/07/image-thumb.png" border="0" alt="image" width="82" height="30" /></a></pre>
<pre class="code"> </pre>
<p>I used this technique to pretty up a very plain GridView display by applying classes to my edit, update and cancel linkbuttons today.  All it took was the creation of a few more CSS classes and linkbutton class tag updates.  <a href="http://johnnycoder.com/blog/wp-content/uploads/2008/07/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://johnnycoder.com/blog/wp-content/uploads/2008/07/image-thumb1.png" border="0" alt="image" width="206" height="244" align="left" /></a></p>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"> </pre>
<pre class="code"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">TemplateField </span><span style="color: #ff0000;">ShowHeader</span><span style="color: #0000ff;">="False"&gt;
    &lt;</span><span style="color: #a31515;">EditItemTemplate</span><span style="color: #0000ff;">&gt;
        &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">LinkButton </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="LinkButton1" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server" </span><span style="color: #ff0000;">CausesValidation</span><span style="color: #0000ff;">="True"
            </span><span style="color: #ff0000;">CommandName</span><span style="color: #0000ff;">="Update" </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="icon-save" </span><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Update"&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">LinkButton</span><span style="color: #0000ff;">&gt;
        &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">LinkButton </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="LinkButton2" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server" </span><span style="color: #ff0000;">CausesValidation</span><span style="color: #0000ff;">="False"
            </span><span style="color: #ff0000;">CommandName</span><span style="color: #0000ff;">="Cancel" </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="icon-cancel" </span><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Cancel"&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">LinkButton</span><span style="color: #0000ff;">&gt;
    &lt;/</span><span style="color: #a31515;">EditItemTemplate</span><span style="color: #0000ff;">&gt;
    &lt;</span><span style="color: #a31515;">ItemTemplate</span><span style="color: #0000ff;">&gt;
        &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">LinkButton </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="LinkButton1" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server" </span><span style="color: #ff0000;">CausesValidation</span><span style="color: #0000ff;">="False"
            </span><span style="color: #ff0000;">CommandName</span><span style="color: #0000ff;">="Edit" </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="icon-edit" </span><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Edit"&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">LinkButton</span><span style="color: #0000ff;">&gt;
    &lt;/</span><span style="color: #a31515;">ItemTemplate</span><span style="color: #0000ff;">&gt;
&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">TemplateField</span><span style="color: #0000ff;">&gt;</span></pre>
<pre class="code"> </pre>
<pre class="code"></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:57aba93a-8ffc-4c17-a984-efc9a6fe299f" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/07/02/linkbutton-image/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/07/02/linkbutton-image/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/07/02/linkbutton-image/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Copy/Paste Lost Due To UpdatePanel</title>
		<link>http://johnnycoder.com/blog/2008/05/25/copypaste-lost-due-to-updatepanel/</link>
		<comments>http://johnnycoder.com/blog/2008/05/25/copypaste-lost-due-to-updatepanel/#comments</comments>
		<pubDate>Sun, 25 May 2008 19:25:44 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2008/05/25/copypaste-lost-due-to-updatepanel/</guid>
		<description><![CDATA[I ran into a strange case this evening.  Rendered text can not be copied to the clipboard after posting back a page containing an UpdatePanel.  Here&#8217;s a simple use case: User enters client name and clicks button to request phone number. Page posts back and displays phone number. User selects the phone number, CTRL+C and [...]]]></description>
			<content:encoded><![CDATA[<pre class="code"></pre>
<p>I ran into a strange case this evening.  Rendered text can not be copied to the clipboard after posting back a page containing an UpdatePanel. </p>
<p>Here&#8217;s a simple use case:</p>
<ol>
<li>User enters client name and clicks button to request phone number.</li>
<li>Page posts back and displays phone number.</li>
<li>User selects the phone number, CTRL+C and attempted to CTRL+V into their contact list.</li>
<li>User gets frustrated because the phone number was selectable but apparently could not be copied.</li>
</ol>
<p>One might assume only the phone number can&#8217;t be copied.  Maybe the changing of the text and visible properties of the associated ASP:Label control is to blame.  Well, that&#8217;s not the case.  ALL text on the page can no longer be copied after the postback. </p>
<p>Basically, add an UpdatePanel to a page, postback and you can&#8217;t copy anything to the clipboard.  By the way, I discovered the problem while using FireFox 2.0. I tested against IE 7 and I wasn&#8217;t able to duplicate the experience.</p>
<p>Try out the most simplistic example I could come up with below.  It might surprise you.</p>
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: #0000ff;">@ </span><span style="color: #a31515;">Page </span><span style="color: #ff0000;">Language</span><span style="color: #0000ff;">="C#" </span><span style="background: #ffee62">%&gt;

</span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">html </span><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://www.w3.org/1999/xhtml"&gt;
&lt;</span><span style="color: #a31515;">head </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"&gt;
    &lt;</span><span style="color: #a31515;">title</span><span style="color: #0000ff;">&gt;</span>Untitled Page<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">title</span><span style="color: #0000ff;">&gt;
&lt;/</span><span style="color: #a31515;">head</span><span style="color: #0000ff;">&gt;
&lt;</span><span style="color: #a31515;">body</span><span style="color: #0000ff;">&gt;
    &lt;</span><span style="color: #a31515;">form </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="form1" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"&gt;
    &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">UpdateProgress </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="UpdateProgress1" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"&gt;
        &lt;</span><span style="color: #a31515;">ProgressTemplate</span><span style="color: #0000ff;">&gt;
            &lt;</span><span style="color: #a31515;">img </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="Img1" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server" </span><span style="color: #ff0000;">src</span><span style="color: #0000ff;">="AjaxIndicator.gif"/&gt;
        &lt;/</span><span style="color: #a31515;">ProgressTemplate</span><span style="color: #0000ff;">&gt;
    &lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">UpdateProgress</span><span style="color: #0000ff;">&gt;
    &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">ScriptManager </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="scriptManager" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"&gt;
    &lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">ScriptManager</span><span style="color: #0000ff;">&gt;
    &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">UpdatePanel </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="updatePanel" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"&gt;
        &lt;</span><span style="color: #a31515;">ContentTemplate</span><span style="color: #0000ff;">&gt;
        &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">Label </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="message" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"&gt;
            </span>This is asp:Label text inside the update panel
                and it can be selected and copied only
                before the postback but not after.<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">Label</span><span style="color: #0000ff;">&gt;
        &lt;</span><span style="color: #a31515;">br </span><span style="color: #0000ff;">/&gt;
        &lt;</span><span style="color: #a31515;">br </span><span style="color: #0000ff;">/&gt;
            </span>This is regular text inside the update panel
                and it acts the same.
        <span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">br </span><span style="color: #0000ff;">/&gt;
        &lt;</span><span style="color: #a31515;">br </span><span style="color: #0000ff;">/&gt;
        &lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">Button </span><span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="button" </span><span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server" </span><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Go" /&gt;
        &lt;/</span><span style="color: #a31515;">ContentTemplate</span><span style="color: #0000ff;">&gt;
    &lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">UpdatePanel</span><span style="color: #0000ff;">&gt;

    </span>This text is outside of the update panel and
    it acts the same as well.

    <span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">form</span><span style="color: #0000ff;">&gt;
&lt;/</span><span style="color: #a31515;">body</span><span style="color: #0000ff;">&gt;
&lt;/</span><span style="color: #a31515;">html</span><span style="color: #0000ff;">&gt;</span></pre>
<pre class="code"></pre>
<div id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:1da92b89-820c-4e7a-a03c-1efa80d8ce6e" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://johnnycoder.com/blog/2008/05/25/copypaste-lost-due-to-updatepanel/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://johnnycoder.com/blog/2008/05/25/copypaste-lost-due-to-updatepanel/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
<p><a href="http://11011.net/software/vspaste"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2008/05/25/copypaste-lost-due-to-updatepanel/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dynamic PDF Reporting for Web Applications</title>
		<link>http://johnnycoder.com/blog/2006/12/04/dynamic-pdf-reporting-for-web-applications/</link>
		<comments>http://johnnycoder.com/blog/2006/12/04/dynamic-pdf-reporting-for-web-applications/#comments</comments>
		<pubDate>Mon, 04 Dec 2006 20:29:46 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/12/04/dynamic-pdf-reporting-for-web-applications/</guid>
		<description><![CDATA[I typically cringe when online reporting is included in a web application&#8217;s feature list. It may just be me, but I&#8217;ve always found building professional, print-friendly reports to be very difficult, very time consuming and error prone. Notwithstanding, I have produced my fair share of dynamic PDF reports over the years and with very few [...]]]></description>
			<content:encoded><![CDATA[<p>I typically cringe when online reporting is included in a web application&#8217;s feature list. It may just be me, but I&#8217;ve always found building professional, print-friendly reports to be very difficult, very time consuming and error prone. Notwithstanding, I have produced my fair share of dynamic PDF reports over the years and with very few exceptions has the reporting solution simply worked without sacrificing a technical requirement or implementing a clever workaround. There are a <span style="text-decoration: underline;">ton</span> of .NET components available to help with report generation. For example, I have recently had some success with ActivePDF, but it has it&#8217;s short-comings so I dedicated some of last week to researching alternative solutions.</p>
<p><strong>SELECTION CRITERIA</strong></p>
<p>1. The component must generate/manage reports in memory rather than requiring a physical file be created. There&#8217;s no need for physical file creation and it&#8217;s best to avoid it if necessary. Simply, it eliminates the need for additional folder permissions and file cleanup.</p>
<p>2. The component must intelligently and inherently handle page breaks. In other words, tables, images and text positioning will be based on available page space. If appropriate, content will wrap or flow from page to page. Additionally, the ability to repeat table headers would be a plus.</p>
<p>3. The component must work for both web and winforms development.</p>
<p>4. The component must produced reports of various page size and orientation. All I need here is the ability to print in portrait or landscape.</p>
<p>5. The component must be inexpensive &#8212; if not free &#8212; with unlimited developer seats and unlimited number of distributions. This is because I am a cheapskate. <img src='http://johnnycoder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>6. The component must have ample examples/templates must be easily available. Documentation is a nice-to-have.</p>
<p>7. It would be nice if the component were production-ready with a proven track record.</p>
<p>8. It would be nice if the component included a designer since a design view can really speed up, umm, design time.</p>
<p><strong>CANDIDATES</strong></p>
<p>Due to my cost requirement (read limitation), I spent most of my time evaluating open source solutions including <a href="http://itextsharp.sourceforge.net/" target="_blank">iTextSharp</a>, <a href="http://sourceforge.net/projects/sharppdf/" target="_blank">SharpPDF</a>, <a href="http://report.sourceforge.net/">Report.NET</a> and <a title="http://nfop.sourceforge.net/" href="http://nfop.sourceforge.net/">NFop</a>. <a href="http://johnnycoder.com/blog/wp-content/uploads/2006/12/WindowsLiveWriter/DynamicReportingforWebApplications_7105/iTexSharp%5B12%5D.png"><img style="margin: 5px 20px" src="http://johnnycoder.com/blog/wp-content/uploads/2006/12/WindowsLiveWriter/DynamicReportingforWebApplications_7105/iTexSharp_thumb%5B10%5D.png" alt="" width="300" height="237" align="right" /></a></p>
<p><a href="http://itextsharp.sourceforge.net/" target="_blank">iTextSharp</a> is a port to C# of the Java <a href="http://www.lowagie.com/iText/">iText</a> library for generating PDF files. Of all the open source options, I was most impressed with iTextSharp. It is stable and actively being developed (version 3.1.7 was released on 11/25) and it comes along with tons of documentation/samples.</p>
<p>Unfortunately, as best as I can tell, iTextSharp requires a physical file be generated. Essentially, a Document object is created and then the iTextSharp PdfWriter listens to the document and directs a PDF-stream to a physical file. The PdfWriter will GetInstance() of a in-memory filestream without throwing an exception, however, the resulting PDF won&#8217;t render. Perhaps it&#8217;s a shortcoming in my code, but I doubt it. My guess is if the component does work with memory streams, examples and documentation would be available. Additionally, iTextSharp doesn&#8217;t gracefully handle page breaks and content wrapping. For these two reasons, I didn&#8217;t go with iTextSharp.</p>
<p><em>UPDATE: Per a <a href="http://johnnycoder.com/blog/2006/12/04/dynamic-pdf-reporting-for-web-applications/#comment-2603">comment </a>from Bruno Lowagie, it appears I was mistaken. One can generate a PDF in memory using iTextSharp. Bruno references his book for more information in his <a href="http://johnnycoder.com/blog/2006/12/04/dynamic-pdf-reporting-for-web-applications/#comment-2603">comment</a>.<br />
</em><br />
I didn&#8217;t spend as much time reviewing SharpPDF, Report.NET and NFop. This was primarily due to lack of documentation/examples to help with my evaluation. <a href="http://sourceforge.net/projects/sharppdf/" target="_blank">SharpPDF</a>, an open-source PDF generator written entirely in C#, looks promising (it handles flowing paragraphs and tables from page to page) but I believe the effort has been somewhat abandoned since its last released was back in February 2005. In conjunction with this, I couldn&#8217;t come up with any samples or documentation (other than NDoc) and I was lead to believe SharpPDF handles PDF generation similarly to iTextSharp (reference to a physical file). In the long run, this SharpPDF probably wouldn&#8217;t have met my needs, but I would like to play with it a little.</p>
<p><strong>AND THE WINNER IS&#8230;</strong></p>
<p><span style="text-decoration: underline;"><a href="http://siberix.com/" target="_blank"><strong>Siberix Report Writer 6.0</strong></a></span></p>
<p>In the end, I opted to go with Siberix Report Writer 6.0 which met every requirement with the exception of having a designer.</p>
<p>For a few days now, I&#8217;ve been working with the trial version (which is conveniently full-featured and simply applies a watermark to the generated report.) I was able to put a reporting framework in place relatively quickly. Of course, my reporting background definitely helped, but I was also able to find a working example for nearly everything I&#8217;ve needed to accomplish in the extensive set of Siberix samples.</p>
<p>On this note, if I were to make one request of Siberix, it would be for more samples which focus on report layout. They do provide one sample project which produces an invoice-like report, but since there is no designer, it would be great if more samples provided &#8220;templated&#8221; layouts.</p>
<p>The component isn&#8217;t free, but it&#8217;s close. It&#8217;s $299 (and the source can be purchased for $2000.) I haven&#8217;t had any issues with the product yet. In my opinion, it&#8217;s definitely worth the investment.</p>
<p><strong>RESOURCE</strong></p>
<p>I was lucky enough to come across a fine <a href="http://www.howtoselectguides.com/dotnet/pdf/" target="_blank">PDF Component for .NET</a> write-up in the How-To-Select Guides series early on in the evaluation period. It provides a very extensive list of &#8220;everything PDF&#8221; from viewers to editors to print drivers. It&#8217;s worth a look.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/12/04/dynamic-pdf-reporting-for-web-applications/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Take Advantage of Application Name</title>
		<link>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/</link>
		<comments>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 07:44:21 +0000</pubDate>
		<dc:creator>Ben Griswold</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/</guid>
		<description><![CDATA[Along with the SQL Server, Database, Username and Password, don&#8217;t forget to include the Application Name in your connection string.  It&#8217;s an optional parameter, but it can be a lifesaver.       Data Source=myServer;      Initial Catalog=myDB;      User Id=myUsername;      Password=myPassword;      Application Name=myApp; Consider this example:  There are multiple .NET applications running on a single web server.  Each application [...]]]></description>
			<content:encoded><![CDATA[<p>Along with the SQL Server, Database, Username and Password, don&#8217;t forget to include the Application Name in your connection string.  It&#8217;s an optional parameter, but it can be a lifesaver. </p>
<p><em>     Data Source=myServer;<br />
     Initial Catalog=myDB;<br />
     User Id=myUsername;<br />
     Password=myPassword;<br />
     <strong>Application Name=myApp;</strong></em></p>
<p>Consider this example:  There are multiple .NET applications running on a single web server.  Each application shares a common SQL Server Server which is suddenly performing very poorly.   You are tasked with determine which of the applications is causing havoc.  You launch SQL Profiler and run a trace.  Since you have included the optional parameter in your connection string, you may now filter the application specific queries and troubleshoot the problem far more effectively.  If you hadn&#8217;t specified the application name, you would have some work ahead of you.  In this case, all of the queries would have had a generic app name, <em>.NET sqlClient Data Provider</em>, and that isn&#8217;t very helpful, is it?  </p>
<p>Do yourself a favor and be sure to add this practice to your coding standards&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

