<?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>onemoretake &#187; ASP.NET</title>
	<atom:link href="http://www.onemoretake.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onemoretake.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 08:28:37 +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>Mocking Session in ASP.NET with Moq and VB.NET</title>
		<link>http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/</link>
		<comments>http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 00:32:04 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Moq]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=302</guid>
		<description><![CDATA[It has been a few years since I have had the chance to explore the latest enhancements to ASP.NET. The development in my day job was locked into traditional ASP.NET forms just before MVC 1.0 was released and there has not been any opportunity to change. TDD, dependency injection and inversion of control containers all [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.onemoretake.com/wp-content/uploads/2010/01/logo.png"><img style="border-right-width: 0px; margin: 0px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="logo" border="0" alt="logo" align="left" src="http://www.onemoretake.com/wp-content/uploads/2010/01/logo_thumb.png" width="123" height="79" /></a> </p>
<p>It has been a few years since I have had the chance to explore the latest enhancements to ASP.NET. The development in my day job was locked into traditional ASP.NET forms just before MVC 1.0 was released and there has not been any opportunity to change. TDD, dependency injection and inversion of control containers all slipped by with me staring at them with my nose pressed against the window. I also develop in php with <a href="http://www.codeigniter.com" target="_blank">CodeIgniter</a>, so I am quite familiar with the idea of MVC and was thoroughly excited when recently, the company I work for, began brewing the idea for a new project. Now was the time to change, so I stocked up on books and blog articles and began the big catch up. I won’t go on about how great MVC is, especially when I spent many hours battling against the web form paradigm &#8211; its such an anti-web way of doing things but with these new ways of working, I now feel a new vigour for .Net web development. </p>
<p>My journey found me working with <a href="http://code.google.com/p/moq/" target="_blank">Moq</a> and although it is pretty self explanatory, most examples and articles are in C# and the documentation for the library is a little sparse. I don’t find the switching between C# and VB.NET very difficult as there is mostly only a syntax difference between them but I did find a problem when, in my unit tests, I needed to assert that entries in the session had been set correctly. So here is how to do it in VB.NET.</p>
<h3>Checking a value has been set in Session</h3>
<p>The first thing that you need is a session object that you can look at in your tests. It needs to inherit from <a href="http://msdn.microsoft.com/en-us/library/system.web.httpsessionstatebase.aspx" target="_blank">HttpSessionStateBase</a> and is pretty simple as the session is just a key-value store &#8211; we can use a generic dictionary to store the values we want to check:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> HttpSessionMock
    <span style="color: #0600FF;">Inherits</span> HttpSessionStateBase
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">ReadOnly</span> objects <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> <span style="color: #008000;">Dictionary</span><span style="color: #000000;">&#40;</span>Of <span style="color: #FF8000;">String</span>, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #0600FF;">Default</span> <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Overloads</span> <span style="color: #FF8000;">Overrides</span> <span style="color: #FF8000;">Property</span> Item<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> name <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>
        <span style="color: #FF8000;">Get</span>
            <span style="color: #FF8000;">Return</span> <span style="color: #0600FF;">If</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>objects.<span style="color: #0000FF;">ContainsKey</span><span style="color: #000000;">&#40;</span>name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, objects<span style="color: #000000;">&#40;</span>name<span style="color: #000000;">&#41;</span>, <span style="color: #FF8000;">Nothing</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span>
        <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>
            objects<span style="color: #000000;">&#40;</span>name<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> value
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span>
    <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Overrides</span> <span style="color: #0600FF;">Sub</span> Add<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> name <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>, <span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>
        objects.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>name, value<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></div></div>

<p>So we now have a session store and we can then use Moq to utilise that in our controller during our test. This is done be setting up a controller context:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"> <span style="color: #008080; font-style: italic;">'Create a real mock session object to check value against</span>
 <span style="color: #0600FF;">Dim</span> session <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> HttpSessionMock<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">'Create a moq controller context</span>
 <span style="color: #0600FF;">Dim</span> mockcontext <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Mock<span style="color: #000000;">&#40;</span>Of ControllerContext<span style="color: #000000;">&#41;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">'Ensure our session object is returned when the session is requested</span>
 mockcontext.<span style="color: #0000FF;">SetupGet</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Function</span><span style="color: #000000;">&#40;</span>c <span style="color: #FF8000;">As</span> ControllerContext<span style="color: #000000;">&#41;</span> c.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span>session<span style="color: #000000;">&#41;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">'set our controller context to be the moq context</span>
 MyController.<span style="color: #0000FF;">ControllerContext</span> <span style="color: #008000;">=</span> mockcontext.<span style="color: #FF0000;">Object</span></pre></div></div>

<p>We can then run our controller action that sets a value in our mock session object and assert that the correct value is set as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">  <span style="color: #008080; font-style: italic;">'run the controller action</span>
 <span style="color: #0600FF;">Dim</span> result <span style="color: #008000;">=</span> MyController.<span style="color: #0000FF;">SomeAction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">'assert the session contains the object we expect</span>
 Assert.<span style="color: #0000FF;">IsInstanceOfType</span><span style="color: #000000;">&#40;</span>session.<span style="color: #0000FF;">Item</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SessionItemToCheck&quot;</span><span style="color: #000000;">&#41;</span>, <span style="color: #804040;">GetType</span><span style="color: #000000;">&#40;</span>ExpectedSessionObject<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">'TODO:other tests to ensure session item is correct</span></pre></div></div>

<h3>Ensuring a value is returned from Session</h3>
<p>You can use the above real mock session object to do this in exactly the same way but we can also setup Moq to return a particular value from session directly:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'create a test object/value we want session to return</span>
<span style="color: #0600FF;">Dim</span> MySessionValue <span style="color: #FF8000;">as</span> <span style="color: #FF8000;">New</span> SomeObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'create our moq controller context</span>
<span style="color: #0600FF;">Dim</span> mockcontext <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Mock<span style="color: #000000;">&#40;</span>Of ControllerContext<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'ensure our test object gets returned by the moq session</span>
mockcontext.<span style="color: #0000FF;">SetupGet</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Function</span><span style="color: #000000;">&#40;</span>c <span style="color: #FF8000;">As</span> ControllerContext<span style="color: #000000;">&#41;</span> c.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SessionItemToTest&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span>MySessionValue<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'assign our context to the controller	</span>
controller.<span style="color: #0000FF;">ControllerContext</span> <span style="color: #008000;">=</span> mockcontext.<span style="color: #FF0000;">Object</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'TODO: run controller action and assert results</span></pre></div></div>

<p>When I look at the code now, I realise that it is quite simple to achieve. However, it took me a little while to get my head around Moq and figure this out as all the examples out there seemed to be trying to do so much more than solely testing session state. It confused me anyhow.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;t=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;title=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;title=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET&amp;summary=%20%20%20It%20has%20been%20a%20few%20years%20since%20I%20have%20had%20the%20chance%20to%20explore%20the%20latest%20enhancements%20to%20ASP.NET.%20The%20development%20in%20my%20day%20job%20was%20locked%20into%20traditional%20ASP.NET%20forms%20just%20before%20MVC%201.0%20was%20released%20and%20there%20has%20not%20been%20any%20opportunity%20to%20change.%20TDD%2C%20dependency%20injection%20and%20inversion%20of%20&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;title=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;Title=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;title=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;t=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/&amp;title=Mocking+Session+in+ASP.NET+with+Moq+and+VB.NET" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Mocking%20Session%20in%20ASP.NET%20with%20Moq%20and%20VB.NET%22&amp;body=Link: http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A %20%20%20It%20has%20been%20a%20few%20years%20since%20I%20have%20had%20the%20chance%20to%20explore%20the%20latest%20enhancements%20to%20ASP.NET.%20The%20development%20in%20my%20day%20job%20was%20locked%20into%20traditional%20ASP.NET%20forms%20just%20before%20MVC%201.0%20was%20released%20and%20there%20has%20not%20been%20any%20opportunity%20to%20change.%20TDD%2C%20dependency%20injection%20and%20inversion%20of%20" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2010/01/17/mocking-session-in-asp-net-with-moq-and-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IIS7 WordPress and Friendly URLs</title>
		<link>http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/</link>
		<comments>http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 06:54:54 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[iis7]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/</guid>
		<description><![CDATA[As a developer who uses Vista as their main OS, I have always found developing php sites a little bit awkward. Php never liked to play nicely with IIS and unless you installed and used Apache, friendly URLs were even more difficult to get working. I use IIS extensively for ASP.NET development and I never [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer who uses Vista as their main OS, I have always found developing php sites a little bit awkward. Php never liked to play nicely with IIS and unless you installed and used Apache, friendly URLs were even more difficult to get working. I use IIS extensively for ASP.NET development and I never liked having both Apache and IIS installed together as they seemed to lock horns at every opportunity. My answer until now was to use <a href="http://www.jcxsoftware.com/vs.php" target="_blank">VS.php</a>, which runs an instance of Apache on demand, so I only have to use Apache when I need to. This was great for the most part but last week I had the situation where I was trying to work on both an ASP.NET project and a WordPress project at the same time. Stopping and starting web servers every few minutes was getting a little dull.</p>
<p><a href="http://www.onemoretake.com/wp-content/uploads/2009/08/rewrite.png"><img title="rewrite" style="border-right: 0px; border-top: 0px; display: inline; margin: 10px 25px 0px 0px; border-left: 0px; border-bottom: 0px" height="198" alt="rewrite" src="http://www.onemoretake.com/wp-content/uploads/2009/08/rewrite_thumb.png" width="314" align="left" border="0" /></a>This spurred me on to take some time to see what all <a href="http://www.itworld.com/development/73001/how-microsoft-made-php-suck-less-windows" target="_blank">the fuss about IIS7 and php was really about</a>. I was pleasantly surprised. Since Vista SP1, it is possible to configure IIS to run php using FastCGI. I won’t go into the detail here, <a href="http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/" target="_blank">there are plenty of examples on how to configure php</a> in this way. Needless to say, it was not too difficult and I had a test phpinfo(); page displaying in no time. What’s particularly great is that Microsoft has been doing some great work getting php to run as quickly and efficiently as it can on IIS. If you are happy running php version 5.3, over at <a href="http://windows.php.net/" target="_blank">Php for Windows</a>, you can pick up a version that has been compiled in Visual Studio 2008 which means faster and more stable than before.</p>
<p>The next step in my investigation was to see what could be done with the new <a href="http://www.iis.net/extensions/URLRewrite" target="_blank">url rewrite module for IIS</a>. Another easy thing to install. What’s more, it has the ability to import .htaccess files. I use these extensively when using Apache and I already had one for the WordPress site I was working on. Importing rules is a pleasure because of the neat interface that shows you which rules it can convert and which it cannot. Editing the original .htaccess directives on-screen allows you to fix those rules it is having trouble with. In my case it was just the RewriteBase, which I could happily remove without worrying about it.</p>
<p>One click of the ‘apply’ button and I was up add running. The site was responsive and low and behold, no issues with the friendly urls. Too easy!</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=IIS7+Wordpress+and+Friendly+URLs+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;t=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs&amp;summary=As%20a%20developer%20who%20uses%20Vista%20as%20their%20main%20OS%2C%20I%20have%20always%20found%20developing%20php%20sites%20a%20little%20bit%20awkward.%20Php%20never%20liked%20to%20play%20nicely%20with%20IIS%20and%20unless%20you%20installed%20and%20used%20Apache%2C%20friendly%20URLs%20were%20even%20more%20difficult%20to%20get%20working.%20I%20use%20IIS%20extensively%20for%20ASP.NET%20development%20and%20I%20&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;Title=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;t=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/&amp;title=IIS7+Wordpress+and+Friendly+URLs" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22IIS7%20Wordpress%20and%20Friendly%20URLs%22&amp;body=Link: http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A As%20a%20developer%20who%20uses%20Vista%20as%20their%20main%20OS%2C%20I%20have%20always%20found%20developing%20php%20sites%20a%20little%20bit%20awkward.%20Php%20never%20liked%20to%20play%20nicely%20with%20IIS%20and%20unless%20you%20installed%20and%20used%20Apache%2C%20friendly%20URLs%20were%20even%20more%20difficult%20to%20get%20working.%20I%20use%20IIS%20extensively%20for%20ASP.NET%20development%20and%20I%20" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/08/31/iis7-wordpress-and-friendly-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Server 2008, ASP.NET, Pre-compiling and Virtual Directories</title>
		<link>http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/</link>
		<comments>http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 23:28:47 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Virtual Directory]]></category>
		<category><![CDATA[Windows Server 2008]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/</guid>
		<description><![CDATA[There has been an interesting problem at work over the last couple of weeks. We are in the process of preparing to move service providers and at the same time upgrading all our servers to run Windows Server 2008 and SQL Server 2008. In preparation for this move, we have been upgrading our staging and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.onemoretake.com/wp-content/uploads/2009/06/windowsserver2008.png"><img title="windowsserver2008" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 20px 0px 0px; border-left: 0px; border-bottom: 0px" height="104" alt="windowsserver2008" src="http://www.onemoretake.com/wp-content/uploads/2009/06/windowsserver2008-thumb.png" width="222" align="left" border="0" /></a> There has been an interesting problem at work over the last couple of weeks. We are in the process of preparing to move service providers and at the same time upgrading all our servers to run Windows Server 2008 and SQL Server 2008. In preparation for this move, we have been upgrading our staging and test servers so we can be sure that everything will work as expected and to iron out the processes, so the move goes as smoothly as possible.</p>
<p>It took about ten minutes before we hit the strangest of problems. It was focused around the way we use a virtual directory to share common code and controls across different websites. The premise is that you create a project to hold your common javascript/images/ascx controls/web services and so on. You then use a virtual directory inside each of your websites that points to the common project. With only <a href="http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx" target="_blank">a small amount of tweaking for the common ascx controls</a> everything seems to work without too much trouble. That is, until you try to do this on Windows Server 2008.</p>
<p>When we started up our web application on our new environment, we noticed almost immediately that the AJAX calls that used the common web service were failing. The error message was suggesting that the project that contained the common web service has not been compiled correctly. By copying the website across to a Windows 2003 server, we deduced that the problem was specific to 2008 as it worked perfectly on 2003. Having exhausted all the developers ideas on why this would be, we called Microsoft and got them involved in troubleshooting the issue.</p>
<p>A few days later an answer came: <em>do not pre-compile your website</em>. Sure enough, build the website without pre-compilation and it worked perfectly. Microsoft’s explanation was that it was due to a change in the way that Windows Server 2008/IIS7 worked. Fairly cryptic I must say and certainly does not leave me satisfied as to why it would not work and what have they done to stop it working. For us, using Windows Server 2008 and IIS7 is more important than the slight performance hit you get when deploying without pre-compilation. For others it may not be such a desirable solution.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;t=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;title=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;title=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories&amp;summary=%20There%20has%20been%20an%20interesting%20problem%20at%20work%20over%20the%20last%20couple%20of%20weeks.%20We%20are%20in%20the%20process%20of%20preparing%20to%20move%20service%20providers%20and%20at%20the%20same%20time%20upgrading%20all%20our%20servers%20to%20run%20Windows%20Server%202008%20and%20SQL%20Server%202008.%20In%20preparation%20for%20this%20move%2C%20we%20have%20been%20upgrading%20our%20staging%20a&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;title=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;Title=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;title=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;t=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/&amp;title=Windows+Server+2008%2C+ASP.NET%2C+Pre-compiling+and+Virtual+Directories" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Windows%20Server%202008%2C%20ASP.NET%2C%20Pre-compiling%20and%20Virtual%20Directories%22&amp;body=Link: http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A %20There%20has%20been%20an%20interesting%20problem%20at%20work%20over%20the%20last%20couple%20of%20weeks.%20We%20are%20in%20the%20process%20of%20preparing%20to%20move%20service%20providers%20and%20at%20the%20same%20time%20upgrading%20all%20our%20servers%20to%20run%20Windows%20Server%202008%20and%20SQL%20Server%202008.%20In%20preparation%20for%20this%20move%2C%20we%20have%20been%20upgrading%20our%20staging%20a" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/06/05/windows-server-2008-aspnet-pre-compiling-and-virtual-directories/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Thanks for Breaking Things ASP.NET 3.5 Team</title>
		<link>http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/</link>
		<comments>http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/#comments</comments>
		<pubDate>Wed, 13 May 2009 06:51:24 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[framework 3.5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=251</guid>
		<description><![CDATA[I have just spent an intense few hours crawling all the JavaScript files in our application (and there are a quite a few) fixing an issue introduced with our upgrade to the .NET framework 3.5. The entire afternoon in fact was spent fixing a single issue: our AJAX calls had stopped working. The first hurdle [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.onemoretake.com/wp-content/uploads/2009/05/broken-glass.jpg"><img title="broken_glass" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 15px 10px 0px; border-left: 0px; border-bottom: 0px" height="184" alt="broken_glass" src="http://www.onemoretake.com/wp-content/uploads/2009/05/broken-glass-thumb.jpg" width="244" align="left" border="0" /></a> I have just spent an intense few hours crawling all the JavaScript files in our application (and there are a quite a few) fixing an issue introduced with our upgrade to the .NET framework 3.5. The entire afternoon in fact was spent fixing a single issue: our AJAX calls had stopped working.</p>
<p>The first hurdle was due to a slightly off-the-norm setup we have for our website. In order to save replicating code across the various websites that make up our solution, we opted for a common virtual directory that serves common assets like JavaScript, images and so on. With a little jiggery pokery, it also allows us to use shared .ascx controls. When we upgraded to the 3.5 framework, the upgrade wizard scans the projects and changes any references that should be pointing the new 3.5 versions. Not all references were changed, as the <a href="http://www.hanselman.com/blog/HowToSetAnIISApplicationOrAppPoolToUseASPNET35RatherThan20.aspx" target="_blank">latest framework sits on top of the 2.0 framework, rather than replaces it</a>. Unfortunately, the upgrade wizard could not figure out that our virtual directory project was not an application at all, so it created an unneeded web.config for it . However, removing that made little difference and it took me quite a while until I found that there were additional script handler settings added for framework 3.5 that were causing the errors. We chose jQuery as the backbone of our JavaScript development and only need to have the .ascx web service handler.</p>
<p>As soon as I removed the unwanted handlers, our AJAX calls sprung into life but still none of our AJAX powered controls worked. A quick look with <a href="http://getfirebug.com/" target="_blank">Firebug</a> revealed the reason. All our JSON responses where wrapped in a {d: } object. A little searching on the interweb and the reason was revealed. As a security measure, <a href="http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/" target="_blank">wrapping the response in that way can stop cross-site scripting attacks</a>.</p>
<p>So why am I annoyed? Well, I cannot fault the reason behind the change, it stops a potentially nasty attack. However, we had no choice in the matter. <strong>It broke every one of our AJAX powered controls</strong>. Just because Microsoft had handled this change in their own AJAX controls, they decided that nobody else would be using the JSON serializer for anything else. As such, they seem to have no configuration setting to turn it off. We had been running the 2.0 AJAX extension with that vulnerability in it for a while, so I think we should at least be allowed to choose whether we continue that way. Instead, I have to spend hours checking all the JavaScript file for AJAX calls and making them look for their data inside the d object.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Thanks+for+Breaking+Things+ASP.NET+3.5+Team+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;t=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;title=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;title=Thanks+for+Breaking+Things+ASP.NET+3.5+Team&amp;summary=%20I%20have%20just%20spent%20an%20intense%20few%20hours%20crawling%20all%20the%20JavaScript%20files%20in%20our%20application%20%28and%20there%20are%20a%20quite%20a%20few%29%20fixing%20an%20issue%20introduced%20with%20our%20upgrade%20to%20the%20.NET%20framework%203.5.%20The%20entire%20afternoon%20in%20fact%20was%20spent%20fixing%20a%20single%20issue%3A%20our%20AJAX%20calls%20had%20stopped%20working.%20%20The%20fir&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;title=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;Title=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;title=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;t=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/&amp;title=Thanks+for+Breaking+Things+ASP.NET+3.5+Team" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Thanks%20for%20Breaking%20Things%20ASP.NET%203.5%20Team%22&amp;body=Link: http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A %20I%20have%20just%20spent%20an%20intense%20few%20hours%20crawling%20all%20the%20JavaScript%20files%20in%20our%20application%20%28and%20there%20are%20a%20quite%20a%20few%29%20fixing%20an%20issue%20introduced%20with%20our%20upgrade%20to%20the%20.NET%20framework%203.5.%20The%20entire%20afternoon%20in%20fact%20was%20spent%20fixing%20a%20single%20issue%3A%20our%20AJAX%20calls%20had%20stopped%20working.%20%20The%20fir" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/05/12/thanks-for-breaking-things-aspnet-35-team/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Captcha Audio with ASP.NET</title>
		<link>http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/</link>
		<comments>http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 05:08:14 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[javacript]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=159</guid>
		<description><![CDATA[The subject of captcha images has been well covered. There are plenty of available resources for creating those warped letters. I created such a control that is a combination of quite a few different ideas and was quite proud of it until not thirty seconds after demonstrating it, someone asked whether it had a &#8216;play [...]]]></description>
			<content:encoded><![CDATA[<p>The subject of <a href="http://www.captcha.net/">captcha</a> images has been well covered. There are plenty of <a href="http://www.codeproject.com/KB/aspnet/CaptchaImage.aspx">available resources</a> for creating those <a href="http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx">warped letters</a>. I created such a control that is a combination of quite a few different ideas and was quite proud of it until not thirty seconds after demonstrating it, someone asked whether it had a &#8216;play audio&#8217; button for blind people. All of a sudden my fancy captcha control was not so fancy.</p>
<p>I tried to suggest using <a href="http://recaptcha.net/">reCaptcha</a> as a solution that had all the bells and whistles, but the customisation of my control trumped the somewhat fixed design of reCaptcha. So the problem of the audio captcha brewed a little in the back of my mind and a month or two later I turned back to it to see if I could find a solution. </p>
<p>A speech synthesis engine was not on the cards, so I figured that because the captcha image was a random collection of letters and numbers, the only way I could generate the appropriate audio was to have audio files of all the letters and numbers. I would then need to join them together, on demand, and play them from the web page. </p>
<p>Creating all the letters and numbers is straight forward enough (cue microphone and best-est speaking voice) and playing audio files from a web page has also become pretty easy thanks to the great <a href="http://schillmania.com/projects/soundmanager2/">SoundManager 2 javascript plugin</a>.</p>
<p>The trickiest part was definitely joining mp3 files that SoundManager requires. MP3 audio files are particularly tricky as they can contain ID1 or ID3 tag information, so just joining them back to back would not create a correct MP3 file. What I needed to do was determine if a particular file had the tag information in it and strip it out if necessary. This took a lot of Googling and studying of the <a href="http://en.wikipedia.org/wiki/MP3">MP3 specification</a> but I eventually managed to ensure the files had no ID2/3 tags in them before joining the files together:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> MP3Concatenator
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Shared</span> <span style="color: #0600FF;">Function</span> <span style="color: #0600FF;">Join</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> MP3sToJoin <span style="color: #FF8000;">As</span> Generic.<span style="color: #0000FF;">List</span><span style="color: #000000;">&#40;</span>Of <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> MemoryStream
        <span style="color: #0600FF;">Dim</span> ms <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MemoryStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> bw <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> BinaryWriter<span style="color: #000000;">&#40;</span>ms<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'loop around each file and remove the tags and then concatenate the files</span>
        <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> mp3File <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> In MP3sToJoin
            <span style="color: #0600FF;">Dim</span> bytes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Byte</span>
            <span style="color: #0600FF;">Dim</span> fs <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> FileStream<span style="color: #000000;">&#40;</span>mp3File, FileMode.<span style="color: #0600FF;">Open</span>, FileAccess.<span style="color: #0000FF;">Read</span>, FileShare.<span style="color: #0000FF;">ReadWrite</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">Dim</span> br <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> BinaryReader<span style="color: #000000;">&#40;</span>fs<span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">Dim</span> audioStart <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Check for ID3 Tags</span>
            fs.<span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
            <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>br.<span style="color: #0000FF;">ReadBytes</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToUpper</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;ID3&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
                <span style="color: #008080; font-style: italic;">'position of the header size bytes</span>
                fs.<span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>
                <span style="color: #008080; font-style: italic;">'MSB of size is Set to 0 and ignored so we need to convert the value</span>
                audioStart <span style="color: #008000;">=</span> BitsToLow<span style="color: #000000;">&#40;</span>br.<span style="color: #0000FF;">ReadBytes</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #008080; font-style: italic;">'add the header end position to this</span>
                audioStart <span style="color: #008000;">+=</span> <span style="color: #FF0000;">9</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Check ID1 Tag</span>
            fs.<span style="color: #FF8000;">Seek</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">128</span>, SeekOrigin.<span style="color: #0600FF;">End</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>System.<span style="color: #0000FF;">Text</span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">ASCII</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>br.<span style="color: #0000FF;">ReadBytes</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToUpper</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;TAG&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
                <span style="color: #008080; font-style: italic;">'there is a ID3v1 tag on the end which needs removing</span>
                fs.<span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> audioStart
                bytes <span style="color: #008000;">=</span> br.<span style="color: #0000FF;">ReadBytes</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span>fs.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">128</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #FF8000;">Else</span>
                fs.<span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> audioStart
                bytes <span style="color: #008000;">=</span> br.<span style="color: #0000FF;">ReadBytes</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span>fs.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
            bw.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span>bytes<span style="color: #000000;">&#41;</span>
            br.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            fs.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Next</span>
&nbsp;
        ms.<span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
        <span style="color: #FF8000;">Return</span> ms
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #FF8000;">Shared</span> <span style="color: #0600FF;">Function</span> BitsToLow<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> Size<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Byte</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span>
        <span style="color: #0600FF;">Dim</span> Ret <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span>
        Ret <span style="color: #008000;">=</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">If</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">128</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">256</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">512</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">1024</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">2048</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">4096</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">64</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">8192</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        <span style="color: #0600FF;">If</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">16384</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">32768</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">65536</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">131072</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">262144</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">524288</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">64</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">1048576</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        <span style="color: #0600FF;">If</span> Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">2097152</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">4194304</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">8388608</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">16777216</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">16</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">33554432</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">67108864</span>
            <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>Size<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #804040;">And</span> <span style="color: #FF0000;">64</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span> Ret <span style="color: #008000;">+=</span> <span style="color: #FF0000;">134217728</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        BitsToLow <span style="color: #008000;">=</span> Ret
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

<p>The trickiest part was handling the ID3 tag, <a href="http://www.id3.org/id3v2.3.0">as the specification states</a>:</p>
<blockquote>
<p>
The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored..</p>
</blockquote>
<p>Which is why I have the BitsToLow function in the code above. </p>
<p>The resulting concatenation is returned as a memory stream because I knew I could output this directly to the Response without writing the concatenated file to disk:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">            ....
            <span style="color: #0600FF;">Dim</span> ms <span style="color: #FF8000;">As</span> IO.<span style="color: #0000FF;">MemoryStream</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
            ms <span style="color: #008000;">=</span> MP3Concatenator.<span style="color: #0600FF;">Join</span><span style="color: #000000;">&#40;</span>MP3FileList<span style="color: #000000;">&#41;</span>
            Response.<span style="color: #0000FF;">ContentType</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;audio/mpeg&quot;</span>
            Response.<span style="color: #0000FF;">ExpiresAbsolute</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">Date</span>.<span style="color: #0000FF;">MinValue</span>
            <span style="color: #0600FF;">If</span> ms <span style="color: #FF8000;">IsNot</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span> Response.<span style="color: #0000FF;">OutputStream</span>.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span>ms.<span style="color: #0000FF;">GetBuffer</span>, <span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span>ms.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            ms.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            Response.<span style="color: #0600FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            ....</pre></td></tr></table></div>

<p>By wiring up the CaptchaAudio.aspx page that returned the concatenated audio to the SoundManager plugin, I could create a link next to the captcha image, that played the letters in the image. Now my captcha control really was fancy.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Captcha+Audio+with+ASP.NET+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;t=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;title=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;title=Captcha+Audio+with+ASP.NET&amp;summary=The%20subject%20of%20captcha%20images%20has%20been%20well%20covered.%20There%20are%20plenty%20of%20available%20resources%20for%20creating%20those%20warped%20letters.%20I%20created%20such%20a%20control%20that%20is%20a%20combination%20of%20quite%20a%20few%20different%20ideas%20and%20was%20quite%20proud%20of%20it%20until%20not%20thirty%20seconds%20after%20demonstrating%20it%2C%20someone%20asked%20wheth&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;title=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;Title=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;title=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;t=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/&amp;title=Captcha+Audio+with+ASP.NET" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Captcha%20Audio%20with%20ASP.NET%22&amp;body=Link: http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A The%20subject%20of%20captcha%20images%20has%20been%20well%20covered.%20There%20are%20plenty%20of%20available%20resources%20for%20creating%20those%20warped%20letters.%20I%20created%20such%20a%20control%20that%20is%20a%20combination%20of%20quite%20a%20few%20different%20ideas%20and%20was%20quite%20proud%20of%20it%20until%20not%20thirty%20seconds%20after%20demonstrating%20it%2C%20someone%20asked%20wheth" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/10/captcha-audio-with-aspnet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Inline Confirm</title>
		<link>http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/</link>
		<comments>http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 02:58:58 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javacript]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=111</guid>
		<description><![CDATA[I have been using Delicious social bookmarking service ever since Blinklist degraded and finally lost the plot with their new design. When I first started using Delicious, a feature of their interface really leapt out at me and I could not wait to include it into a project. The feature I am talking about is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://www.delicious.com/">Delicious</a> social bookmarking service ever since <a href="http://www.blinklist.com/">Blinklist </a> degraded and finally lost the plot with their new design. When I first started using Delicious, a feature of their interface really leapt out at me and I could not wait to include it into a project.<br />
The feature I am talking about is their inline confirmation. That is, when you, for instance, delete a bookmark by clicking on the delete link, the link is replaced with an &#8216;Are You Sure? Yes/Cancel&#8217; message. </p>
<p><img src="http://www.onemoretake.com/wp-content/uploads/2009/03/inlineconfirmbefore.jpg" alt="Inline Confirm - Before" title="Inline Confirm - Before" width="366" height="49" class="size-full wp-image-116" /></p>
<p><img src="http://www.onemoretake.com/wp-content/uploads/2009/03/inlineconfirmafter.jpg" alt="Inline Confirm - After" title="Inline Confirm - After" width="367" height="46" class="size-full wp-image-115" /></p>
<p>I really liked this as there was no page refresh for the confirmation message and it was not a modal popup, which is a little obtrusive at best. It also occurred to me that something like that would not require a huge amount of code either. This is what I came up with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">inlineconfirm</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> callback<span style="color: #339933;">,</span> parentSel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> hideEl <span style="color: #339933;">=</span> parentSel <span style="color: #339933;">?</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span>parentSel<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        hideEl.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;confirm&quot;&gt;Are you sure? &lt;a class=&quot;confirmyes&quot; href=&quot;#&quot;&gt;Yes&lt;/a&gt; &lt;span&gt;|&lt;/span&gt; &lt;a class=&quot;confirmcancel&quot; href=&quot;#&quot;&gt;Cancel&lt;/a&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.confirmyes'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> hideEl.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.confirm:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.confirmcancel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> hideEl.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.confirm:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>hideEl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I decided on using just a function rather than a plugin, as I wanted asp.net control compatibility (see later).  The function just swaps out the element(s) for the confirmation message and puts them back if cancel is pressed, otherwise it runs the callback. It utilises three parameters: </p>
<ul>
<li><strong>el</strong> &#8211; The element which initiates the inline confirm. i.e. The link</li>
<li><strong>callback</strong> &#8211; A function to run if the answer is Yes</li>
<li><strong>parentSel</strong> &#8211; (optional) This is a jquery selector that identifies a parent element of <strong>el</strong> that will be replaced with the prompt. This is so that you could for instance hide an entire section of html with the &#8216;are you sure?&#8217; prompt. Particularly useful to keep layouts consistent.</li>
</ul>
<p>This is a nice easy function to use in most web development language, however, if you are using asp.net, it becomes difficult to use it with the asp controls like &lt;asp:Button /&gt; or &lt;asp:LinkButton /&gt;. This is because ASP.NET likes to take control of the click events of these so that it can create its event model at the server. There is the onClientClick property which allows us to have some control over the click event but we need to pass a callback function. After a little investigating, I discovered the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.getpostbackeventreference(VS.80).aspx">GetPostBackEventReference</a> function:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">mylinkbutton.<span style="color: #0000FF;">OnClientClick</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;$.inlineconfirm(this,function() {&quot;</span> <span style="color: #008000;">&amp;</span> ClientScript.<span style="color: #0000FF;">GetPostBackEventReference</span><span style="color: #000000;">&#40;</span>mylinkbutton, <span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;;});return false;&quot;</span></pre></div></div>

<p>The GetPostBackEventReference returns a string of the function that will be used to invoke the postback. Just what we needed.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=jQuery+Inline+Confirm+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;t=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;title=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;title=jQuery+Inline+Confirm&amp;summary=I%20have%20been%20using%20Delicious%20social%20bookmarking%20service%20ever%20since%20Blinklist%20%20degraded%20and%20finally%20lost%20the%20plot%20with%20their%20new%20design.%20When%20I%20first%20started%20using%20Delicious%2C%20a%20feature%20of%20their%20interface%20really%20leapt%20out%20at%20me%20and%20I%20could%20not%20wait%20to%20include%20it%20into%20a%20project.%0D%0AThe%20feature%20I%20am%20talkin&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;title=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;Title=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;title=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;t=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/&amp;title=jQuery+Inline+Confirm" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22jQuery%20Inline%20Confirm%22&amp;body=Link: http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20have%20been%20using%20Delicious%20social%20bookmarking%20service%20ever%20since%20Blinklist%20%20degraded%20and%20finally%20lost%20the%20plot%20with%20their%20new%20design.%20When%20I%20first%20started%20using%20Delicious%2C%20a%20feature%20of%20their%20interface%20really%20leapt%20out%20at%20me%20and%20I%20could%20not%20wait%20to%20include%20it%20into%20a%20project.%0D%0AThe%20feature%20I%20am%20talkin" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Templating Your ASP.NET Pages</title>
		<link>http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/</link>
		<comments>http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 22:24:34 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ascx]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[user control]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=62</guid>
		<description><![CDATA[The majority of my ASP.NET development time is spent on web applications. Recently however, I was creating a marketing website to complement one of those applications and realised it required a slightly different approach to that which I was used to &#8211; we needed maximum changeability for as little downtime. Switching off the option to [...]]]></description>
			<content:encoded><![CDATA[<p>The majority of my ASP.NET development time is spent on web applications. Recently however, I was creating a marketing website to complement one of those applications and realised it required a slightly different approach to that which I was used to &#8211; we needed maximum changeability for as little downtime.  Switching off the option to compile the pages into the dlls was the first step but I wanted pages with as little structural code in them as possible, as they may be edited by a non-developer. I discovered that the use of template user controls was the answer to this and meant that the pages would contain controls similar to this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uc:contentarea</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mycontent&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;headingcontent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Some Heading<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/headingcontent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maincontent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Lorem ipsum..<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/maincontent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uc:contentarea<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In this way, any html code that affects the layout would be hidden away and anyone changing them cannot accidently break the layout.  How does one do this? It is fairly straight forward. First you create a new user control and write the html as you want it, with the areas where the content is to be inserted marked to run at server:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mycontentcontrol&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;heading&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The differences to a standard user control occur in the codebehind:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">ComponentModel</span>
Partial <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> MyControl
    <span style="color: #0600FF;">Inherits</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">UserControl</span>
    <span style="color: #FF8000;">Private</span> _headingTemplate <span style="color: #FF8000;">As</span> ITemplate <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
    <span style="color: #FF8000;">Private</span> _contentTemplate <span style="color: #FF8000;">As</span> ITemplate <span style="color: #008000;">=</span> <span style="color: #FF8000;">Nothing</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Page_Init<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Init</span>
        <span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> <span style="color: #000000;">&#40;</span>HeadingContent <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #0600FF;">Dim</span> container <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> ContentContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            HeadingContent.<span style="color: #0000FF;">InstantiateIn</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span>
            heading.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span>
            heading.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        <span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> <span style="color: #000000;">&#40;</span>MainContent <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #0600FF;">Dim</span> container <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> ContentContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            MainContent.<span style="color: #0000FF;">InstantiateIn</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span>
            content.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span>
            content.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    &lt;TemplateContainer<span style="color: #000000;">&#40;</span><span style="color: #804040;">GetType</span><span style="color: #000000;">&#40;</span>ContentContainer<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, _
       PersistenceMode<span style="color: #000000;">&#40;</span>PersistenceMode.<span style="color: #0000FF;">InnerProperty</span><span style="color: #000000;">&#41;</span>, _
       TemplateInstance<span style="color: #000000;">&#40;</span>TemplateInstance.<span style="color: #0000FF;">Single</span><span style="color: #000000;">&#41;</span>, _
       Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">False</span><span style="color: #000000;">&#41;</span>&gt; _
   <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Property</span> HeadingContent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> ITemplate
        <span style="color: #FF8000;">Get</span>
            <span style="color: #FF8000;">Return</span> _headingTemplate
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span>
        <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> ITemplate<span style="color: #000000;">&#41;</span>
            _headingTemplate <span style="color: #008000;">=</span> value
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span>
    <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span>
&nbsp;
    &lt;TemplateContainer<span style="color: #000000;">&#40;</span><span style="color: #804040;">GetType</span><span style="color: #000000;">&#40;</span>ColumnContainer<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, _
        PersistenceMode<span style="color: #000000;">&#40;</span>PersistenceMode.<span style="color: #0000FF;">InnerProperty</span><span style="color: #000000;">&#41;</span>, _
        TemplateInstance<span style="color: #000000;">&#40;</span>TemplateInstance.<span style="color: #0000FF;">Single</span><span style="color: #000000;">&#41;</span>, _
        Browsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">False</span><span style="color: #000000;">&#41;</span>&gt; _
    <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Property</span> MainContent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> ITemplate
        <span style="color: #FF8000;">Get</span>
            <span style="color: #FF8000;">Return</span> _contentTemplate
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span>
        <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> ITemplate<span style="color: #000000;">&#41;</span>
            _contentTemplate <span style="color: #008000;">=</span> value
        <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span>
    <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> ContentContainer
        <span style="color: #0600FF;">Inherits</span> Control
        <span style="color: #0600FF;">Implements</span> INamingContainer
&nbsp;
        <span style="color: #FF8000;">Friend</span> <span style="color: #0600FF;">Sub</span> <span style="color: #FF8000;">New</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

<p>There is quite a lot here but it is fairly straight forward. The key to it is using the ITemplate interface for the properties that represent each of the areas you want as editable. This allows you to place the tags within the control in your page.  At runtime , the content of these is placed into a control &#8211; the ContentContainer class, using the InstantiateIn method and that control is then placed into the html.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Templating+Your+ASP.NET+Pages+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;t=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;title=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;title=Templating+Your+ASP.NET+Pages&amp;summary=The%20majority%20of%20my%20ASP.NET%20development%20time%20is%20spent%20on%20web%20applications.%20Recently%20however%2C%20I%20was%20creating%20a%20marketing%20website%20to%20complement%20one%20of%20those%20applications%20and%20realised%20it%20required%20a%20slightly%20different%20approach%20to%20that%20which%20I%20was%20used%20to%20-%20we%20needed%20maximum%20changeability%20for%20as%20little%20do&amp;source=onemoretake" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;title=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;Title=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;title=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;t=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/&amp;title=Templating+Your+ASP.NET+Pages" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Templating%20Your%20ASP.NET%20Pages%22&amp;body=Link: http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A The%20majority%20of%20my%20ASP.NET%20development%20time%20is%20spent%20on%20web%20applications.%20Recently%20however%2C%20I%20was%20creating%20a%20marketing%20website%20to%20complement%20one%20of%20those%20applications%20and%20realised%20it%20required%20a%20slightly%20different%20approach%20to%20that%20which%20I%20was%20used%20to%20-%20we%20needed%20maximum%20changeability%20for%20as%20little%20do" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/02/templating-your-aspnet-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
