<?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>Playing with .Net</title>
	<atom:link href="http://www.playingwith.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.playingwith.net</link>
	<description>Playing around with Microsoft technology</description>
	<lastBuildDate>Tue, 28 Feb 2012 18:36:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>My TechDaysNL 2012 session is online</title>
		<link>http://www.playingwith.net/2012/02/my-techdaysnl-2012-session-is-online/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-techdaysnl-2012-session-is-online</link>
		<comments>http://www.playingwith.net/2012/02/my-techdaysnl-2012-session-is-online/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 18:33:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2011]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[metro design principles]]></category>
		<category><![CDATA[metro style]]></category>
		<category><![CDATA[techdays]]></category>
		<category><![CDATA[techdaysnl]]></category>
		<category><![CDATA[winjs]]></category>

		<guid isPermaLink="false">http://www.playingwith.net/?p=230</guid>
		<description><![CDATA[Friday 17 February I gave a presentation about Windows 8 ‘metro style’ development with JavaScript on the TechDays 2012 event in Den Hague, The Netherlands. In this session I have covered the following topics: - Metro design principles - WinRT architecture - WinJS library - Demo’s on how to create your own ‘metro style’ app ...<p class="read-more"><a href="http://www.playingwith.net/2012/02/my-techdaysnl-2012-session-is-online/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Friday 17 February I gave a presentation about Windows 8 ‘metro style’ development with JavaScript on the TechDays 2012 event in Den Hague, The Netherlands.</p>
<p>In this session I have covered the following topics:</p>
<ul>
<li>- Metro design principles</li>
<li>- WinRT architecture</li>
<li>- WinJS library</li>
<li>- Demo’s on how to create your own ‘metro style’ app with Javascript.</li>
</ul>
<p>Below you will find the recording of the session. Warning for my non-dutch readers: The session is spoken in <strong>Dutch</strong>.</p>
<p>&nbsp;</p>
<p><iframe style="width: 652px; height: 414px;" src="http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2480/player?w=652&amp;h=400" frameborder="0" scrolling="no" width="320" height="240"></iframe></p>
<p>Hope you enjoyed being at the Techdays 2012 and watching my session, or seeing it online on Channel 9.</p>
<p>If you have any questions about the presentation or the content don&#8217;t hesistate to contact me via the comments or via twitter <a href="http://www.twitter.com/bloodyairtimer">@bloodyairtimer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2012/02/my-techdaysnl-2012-session-is-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading your MVC 3 project to the MVC 4 beta</title>
		<link>http://www.playingwith.net/2012/02/upgrading-your-mvc-3-project-to-the-mvc-4-beta/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=upgrading-your-mvc-3-project-to-the-mvc-4-beta</link>
		<comments>http://www.playingwith.net/2012/02/upgrading-your-mvc-3-project-to-the-mvc-4-beta/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 17:57:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC 4]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[mvc3]]></category>
		<category><![CDATA[mvc4]]></category>
		<category><![CDATA[upgrade mvc 3]]></category>

		<guid isPermaLink="false">http://www.playingwith.net/?p=224</guid>
		<description><![CDATA[Last week the MVC 4 beta is released with support for a “go-live” license. Which means that it’s in a state where we can build and deploy our applications with this beta. So I decided to take my ‘old’ MVC 3 project and upgrade it to the MVC 4 beta. First I installed the MVC ...<p class="read-more"><a href="http://www.playingwith.net/2012/02/upgrading-your-mvc-3-project-to-the-mvc-4-beta/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Last week the MVC 4 beta is released with support for a <a href="http://weblogs.asp.net/scottgu/archive/2012/02/19/asp-net-mvc-4-beta.aspx" target="_blank">“go-live”</a> license. Which means that it’s in a state where we can build and deploy our applications with this beta.</p>
<p>So I decided to take my ‘old’ MVC 3 project and upgrade it to the MVC 4 beta. First I installed the MVC 4 Beta on my developer machine. (You can download it <a href="http://www.asp.net/mvc/mvc4" target="_blank">here</a>) (Please make sure that you have the correct .Net framework version on your machine. During installation your environment will be checked for .Net 4.0 framework and that you don’t have the .Net Framework 4.5 installed)</p>
<p>After the installation I took the steps to upgrade from MVC 3 to MVC 4 Beta which are described in the release notes. You can find these steps  <a href="http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806" target="_blank">here</a>.</p>
<p>So far so good……</p>
<p>When I tried to run my project, I get exceptions that it’s expecting version 2.0.0.0 for the System.Web.* dll’s. I did a clean solution and a  rebuild. No luck!</p>
<p>Than I remembered that I used the <strong>“Add deployable dependencies”</strong> feature in Visual Studio to make sure that the correct dll’s are copied when I publish my solution to my hosting provider. (I used this feature because my hosting provider didn’t has MVC 3 installed when I published my website.)</p>
<p>I removed all files from the <strong>“_bin_deployableAssemblies”</strong> folder in my solution. Than right clicked my webproject, clicked <strong>“Add Deployable Dependencies”</strong> and re-added the assemblies.</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2012/02/DeployableAssemblies.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="DeployableAssemblies" src="http://www.playingwith.net/wp-content/uploads/2012/02/DeployableAssemblies_thumb.png" alt="DeployableAssemblies" width="309" height="417" border="0" /></a></p>
<p>After re-adding the assemblies I rebuild my solution and started it. Now the errors are gone!</p>
<p>Hope this helps someone having also issues upgrading to MVC 4.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2012/02/upgrading-your-mvc-3-project-to-the-mvc-4-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m speaking at TechDays 2012</title>
		<link>http://www.playingwith.net/2012/01/im-speaking-at-techdays-2012/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=im-speaking-at-techdays-2012</link>
		<comments>http://www.playingwith.net/2012/01/im-speaking-at-techdays-2012/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 11:22:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinJS]]></category>
		<category><![CDATA[den haag]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[metro style]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[techdays 2012]]></category>

		<guid isPermaLink="false">http://www.playingwith.net/?p=212</guid>
		<description><![CDATA[The last few years I have been attending the DevDays (which are now callled TechDays) and always had alot of fun being there with colleagues, catch up with some guys and learning alot of the sessions being held during these days. This year will be totally different, because this year I will be doing a ...<p class="read-more"><a href="http://www.playingwith.net/2012/01/im-speaking-at-techdays-2012/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>The last few years I have been attending the DevDays (which are now callled TechDays) and always had alot of fun being there with colleagues, catch up with some guys and learning alot of the sessions being held during these days. This year will be totally different, because this year I will be doing a session myself.</p>
<p><a href="http://www.playingwith.net/2012/01/im-speaking-at-techdays-2012/badge_speaking/" rel="attachment wp-att-214"><img class="alignnone size-full wp-image-214" title="I'm speaking at TechDays 2012" src="http://www.playingwith.net/wp-content/uploads/2012/01/badge_speaking.png" alt="" width="263" height="170" /></a></p>
<p>I will be speaking about developing <strong>Metro style</strong> apps in <strong>Windows 8</strong> with Javascript. In this session I will guide you through the different steps to build your own &#8216;metro style&#8217; app. In this session I will cover the following topics:</p>
<ul>
<li>Promisses</li>
<li>Dataloading with XHR (asynchronous)</li>
<li>Datatemplates</li>
<li>Databinding</li>
<li>Adding controls to the AppBar</li>
<li>Livetiles</li>
<li>Navigation</li>
</ul>
<p>For most of the above points I will also show you in demo&#8217;s how to do this by yourself. I&#8217;m pretty sure that after this session you will say: &#8220;Wow, that&#8217;s really easy to start developing &#8216;Metro style&#8217; apps with Javascript!&#8221;.</p>
<p>I really hope to see you on Friday 17 february in Den Hague! More details about my session can be found at the <a href="http://www.techdays.nl/AgendaDetail.aspx?cid=2480" target="_blank">Techdays site</a></p>
<p>Last thing to say is that I&#8217;m really proud to have this opportunity to speak at an event like this size.</p>
<p>See you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2012/01/im-speaking-at-techdays-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a dynamic layout with XAML in Windows 8 &#8216;Metro style&#8217; apps</title>
		<link>http://www.playingwith.net/2012/01/creating-a-dynamic-layout-with-xaml-in-windows-8-metro-style-apps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-a-dynamic-layout-with-xaml-in-windows-8-metro-style-apps</link>
		<comments>http://www.playingwith.net/2012/01/creating-a-dynamic-layout-with-xaml-in-windows-8-metro-style-apps/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 19:51:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[dotnetmag]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[dynamic layout]]></category>
		<category><![CDATA[metro style]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.playingwith.net/?p=206</guid>
		<description><![CDATA[A big percentage of all apps is showing data to the user, formatted in different ways. Sometimes it are images, the other time graphs, but a lot of times you use a data grid to present your data to the user. To present this data in the most smooth way to the user, you often ...<p class="read-more"><a href="http://www.playingwith.net/2012/01/creating-a-dynamic-layout-with-xaml-in-windows-8-metro-style-apps/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>A big percentage of all apps is showing data to the user, formatted in different ways. Sometimes it are images, the other time graphs, but a lot of times you use a data grid to present your data to the user. To present this data in the most smooth way to the user, you often want to make the columns / rows scalable. With this approach the data is shown in the most comfortable way to the user when they use different devices and resolutions. When using XAML in your Windows 8 metro style app, you can easily define a dynamic layout for your grid by using the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.columndefinition.aspx" target="_blank">ColumnDefinition</a> and/or <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.rowdefinition.aspx" target="_blank">RowDefinition</a> classes.</p>
<p>Below I will show you the XAML of an dynamic layout grid and will tell you about the used properties and how to add controls to the different positions created in the grid.</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:b5ee4aa4-9df1-407f-afb1-80d7df9223a2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
<pre style=" width: 452px; height: 143px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">&lt;</span><span style="color: #800000;">Grid </span><span style="color: #FF0000;">x:Name</span><span style="color: #0000FF;">=&quot;LayoutRoot&quot;</span><span style="color: #FF0000;"> Background</span><span style="color: #0000FF;">=&quot;#FF0C0C0C&quot;</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">2</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">3</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">4</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;*&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">5</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;">  </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">6</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;2*&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">7</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">8</span> <span style="color: #000000;"></span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">Grid</span><span style="color: #0000FF;">&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>As you can see above right now we only use the ColumnDefinitions to define the columns in our grid. You can see this as the skeleton for our grid. Later we will make sure that every columndefinition will have the right controls added to it.</p>
<p>In this article we only focus on the (easy) dynamic part of the layout. In later articles I will talk about a more complex dynamic layout. That’s why we for now will only talk about the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.columndefinition.width.aspx" target="_blank">Width</a> property. The Width property can be assigned with the following values: Auto, * or a double value.</p>
<table cellspacing="0" cellpadding="2" width="400" border="0">
<tbody>
<tr>
<td valign="top" width="87"><strong>Auto</strong></td>
<td valign="top" width="313">The size is determined by the size properties of the content object. </td>
</tr>
<tr>
<td valign="top" width="87"><strong>*</strong></td>
<td valign="top" width="313">The value is expressed as a weighted proportion of available space. </td>
</tr>
<tr>
<td valign="top" width="87"><strong>Double value</strong></td>
<td valign="top" width="313">The value is expressed in pixels. </td>
</tr>
</tbody>
</table>
<p>So if you have a columndefinition with width set to Auto and you add a control to the column that has a width of 100 pixels, than your column will be 100 pixels + a small amount needed for borders etc. You can see Auto as the fit to content option.</p>
<p>* is the option if you want to make sure that your grid is filled up 100%, because this one will fill up the space that is left after all other columndefinitions have taken their space. If you have multiple columns with Width=”*” than the width will be equally divided over the columns. In our example you see that the third column definition has the width set to “2*”. This means that this column will take up twice as much space as the other column. If there is for example 300 pixels left in our grid, than column 1 will get 100 pixels and column 3 will get 200 pixels.</p>
<p>The last option is setting a width to a double value. This value is the exact value in pixels that the column will take.</p>
<p><strong>Adding controls to the grid</strong></p>
<p>Okay, lets add some controls to the grid to see how that works. First I will show you the full example of the dynamic layout grid, further I will explain what’s happening.</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:1e4a2bc2-7eb5-4def-a1da-963343980ab7" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">
<pre style=" width: 606px; height: 218px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #0000FF;">&lt;</span><span style="color: #800000;">Grid </span><span style="color: #FF0000;">x:Name</span><span style="color: #0000FF;">=&quot;LayoutRoot&quot;</span><span style="color: #FF0000;"> Background</span><span style="color: #0000FF;">=&quot;#FF0C0C0C&quot;</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;*&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;">  </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 6</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">ColumnDefinition </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;2*&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">Grid.ColumnDefinitions</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 8</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">TextBlock </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;"> Text</span><span style="color: #0000FF;">=&quot;Column 1&quot;</span><span style="color: #FF0000;"> Grid.Column</span><span style="color: #0000FF;">=&quot;0&quot;</span><span style="color: #0000FF;">&gt;&lt;/</span><span style="color: #800000;">TextBlock</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">Button </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;"> Content</span><span style="color: #0000FF;">=&quot;Column 2&quot;</span><span style="color: #FF0000;"> Grid.Column</span><span style="color: #0000FF;">=&quot;1&quot;</span><span style="color: #0000FF;">&gt;&lt;/</span><span style="color: #800000;">Button</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">10</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">TextBlock </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;"> Text</span><span style="color: #0000FF;">=&quot;Column 3&quot;</span><span style="color: #FF0000;"> Grid.Column</span><span style="color: #0000FF;">=&quot;2&quot;</span><span style="color: #0000FF;">&gt;&lt;/</span><span style="color: #800000;">TextBlock</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">11</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">Button </span><span style="color: #FF0000;">Width</span><span style="color: #0000FF;">=&quot;Auto&quot;</span><span style="color: #FF0000;"> Content</span><span style="color: #0000FF;">=&quot;Column 4&quot;</span><span style="color: #FF0000;"> Grid.Column</span><span style="color: #0000FF;">=&quot;3&quot;</span><span style="color: #0000FF;">&gt;&lt;/</span><span style="color: #800000;">Button</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">12</span> <span style="color: #000000;"></span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">Grid</span><span style="color: #0000FF;">&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>As you can see in the above example we just start adding controls to are grid right after the ColumnDefinitions element. In our example we added two text blocks and two buttons. With the Grid.Column property we can define in which column these controls are added. Adding the controls to the grid can be done in a random order if you want. As you can see the Grid.Column property is a zero-based index.</p>
<p>Below is a screenshot of the dynamic layout that we created with the above XAML code.</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2012/01/DynamicLayout.png"><img title="DynamicLayout" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="DynamicLayout" src="http://www.playingwith.net/wp-content/uploads/2012/01/DynamicLayout_thumb.png" width="590" height="258" /></a></p>
<p>You can repeat these above steps in the same way for rows. But than in the Grid.RowDefinitions. If you want to add a control to a specific row in your grid you should add the Grid.Row property to your control to define the row where you want your control to appear.</p>
<p>In a later post I will talk about a more complex dynamic layout and how you can measure the width/height of the columns/rows that are created with the * option. Also we will have a look at how work with these kind of layouts from the code behind.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2012/01/creating-a-dynamic-layout-with-xaml-in-windows-8-metro-style-apps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL sessionState provider adding strange ID to MVC3 url</title>
		<link>http://www.playingwith.net/2011/11/mysql-sessionstate-provider-adding-strange-id-to-mvc3-url/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-sessionstate-provider-adding-strange-id-to-mvc3-url</link>
		<comments>http://www.playingwith.net/2011/11/mysql-sessionstate-provider-adding-strange-id-to-mvc3-url/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 20:26:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[membershipprovider]]></category>
		<category><![CDATA[mvc3]]></category>
		<category><![CDATA[sessionstate]]></category>

		<guid isPermaLink="false">http://www.playingwith.net/?p=201</guid>
		<description><![CDATA[Tonight I was working on an MVC3 project, which uses an MySQL database. For the admin area I’m using the MySQL membership provider to add users and roles. While clicking through the ASP.NET configuration wizard I have enabled all options for the MySQL membership provider. After I ran the configuration wizard I started my project ...<p class="read-more"><a href="http://www.playingwith.net/2011/11/mysql-sessionstate-provider-adding-strange-id-to-mvc3-url/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Tonight I was working on an MVC3 project, which uses an MySQL database. For the admin area I’m using the MySQL membership provider to add users and roles. While clicking through the ASP.NET configuration wizard I have enabled all options for the MySQL membership provider.</p>
<p>After I ran the configuration wizard I started my project to check if the users and roles where working. It didn’t. HttpPost actions where not executed, instead the HttpGet action was executed. After a while I found out that there was a strange kind of folder / query string added to my url.</p>
<p><a title="http://localhost/JecorWebshop/(S(0swhj3f12244dysv5nj445gx))/" href="http://localhost/(S(0swhj3f12244dysv5nj445gx))/">http://localhost/(S(0swhj3f12244dysv5nj445gx))/</a></p>
<p>I really had no idea where this thing came from. Compared my solution to another solution (I first checked if this solution was still working) and after a while I found out that my other solution was only using a few options of the MySQL membership provider. Than I started removing parts of the membership that I don’t really needed. After removing the sessionState provider the url was working normal again.</p>
<p>See below codeblock that I removed from my solution</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:4b84dc80-ac12-46fe-af0e-9ffd9c25694f" class="wlWriterEditableSmartContent">
<pre style=" width: 614px; height: 111px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">&lt;</span><span style="color: #800000;">sessionState </span><span style="color: #FF0000;">mode</span><span style="color: #0000FF;">=&quot;Custom&quot;</span><span style="color: #FF0000;"> cookieless</span><span style="color: #0000FF;">=&quot;true&quot;</span><span style="color: #FF0000;"> regenerateExpiredSessionId</span><span style="color: #0000FF;">=&quot;true&quot;</span><span style="color: #FF0000;"> customProvider</span><span style="color: #0000FF;">=&quot;MySqlSessionStateProvider&quot;</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">2</span> <span style="color: #000000;">  </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">providers</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">3</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">add </span><span style="color: #FF0000;">name</span><span style="color: #0000FF;">=&quot;MySqlSessionStateProvider&quot;</span><span style="color: #FF0000;"> type</span><span style="color: #0000FF;">=&quot;MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d&quot;</span><span style="color: #FF0000;">
</span><span style="color: #008080;">4</span> <span style="color: #FF0000;">         applicationName</span><span style="color: #0000FF;">=&quot;my app&quot;</span><span style="color: #FF0000;"> description</span><span style="color: #0000FF;">=&quot;my app&quot;</span><span style="color: #FF0000;"> connectionStringName</span><span style="color: #0000FF;">=&quot;MyAppDB&quot;</span><span style="color: #FF0000;"> writeExceptionsToEventLog</span><span style="color: #0000FF;">=&quot;False&quot;</span><span style="color: #FF0000;"> autogenerateschema</span><span style="color: #0000FF;">=&quot;True&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">5</span> <span style="color: #000000;">  </span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">providers</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">6</span> <span style="color: #000000;"></span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">sessionState</span><span style="color: #0000FF;">&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Well that’s it. Seems like that MySQL sessionstate and MVC3 are not really working together.</p>
<p>I haven’t checked out why this behavior is occurring or if it’s also happening when using the ‘standard’ sessionstate provider. If you have any ideas please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2011/11/mysql-sessionstate-provider-adding-strange-id-to-mvc3-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Integrate&quot; Bing Maps directions in your WP7 app</title>
		<link>http://www.playingwith.net/2011/07/integrate-bing-maps-directions-in-your-wp7-app/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=integrate-bing-maps-directions-in-your-wp7-app</link>
		<comments>http://www.playingwith.net/2011/07/integrate-bing-maps-directions-in-your-wp7-app/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 11:27:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bing]]></category>
		<category><![CDATA[Bing maps]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dotnetmag]]></category>
		<category><![CDATA[Mango]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Bing Maps]]></category>
		<category><![CDATA[Directions]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://chris-online.nl/?p=158</guid>
		<description><![CDATA[in the upcoming “Mango” update for Windows Phone 7, Microsoft has already released the Windows Phone Developer Tools Beta 2 for this new version which has got version number 7.1. One of the new cool features which is included in this beta release is the support to use the “Directions” feature in Bing Maps from ...<p class="read-more"><a href="http://www.playingwith.net/2011/07/integrate-bing-maps-directions-in-your-wp7-app/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>in the upcoming “Mango” update for Windows Phone 7, Microsoft has already released the <a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/06/29/developers-get-goody-basket-full-of-mangos.aspx" target="_blank">Windows Phone Developer Tools Beta 2</a> for this new version which has got version number 7.1.</p>
<p>One of the new cool features which is included in this beta release is the support to use the “Directions” feature in Bing Maps from your app. This feature makes it very easy to make a location aware app and makes it interactive to the user to help him find a specific spot. (Think about an app that helps users find only your restaurants, ATM’s, your company or anything else that has a coordinate)</p>
<p><em>Please note that I&#8217;m trying to keep away from the “integrate” part, cause actually it’s not integrating but more like navigating away from your app to Bing Maps with the location you specified in your app.</em></p>
<p>Okay, bring on this new feature and show us how to do this.</p>
<p>First, let’s start with the introduction of this feature/class/task or how you want to call it. We are talking about the <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.bingmapsdirectionstask(v=vs.92).aspx" target="_blank">BingMapsDirectionsTask</a> which is a very simple class that lives in the <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks(v=vs.92).aspx">Microsoft.Phone.Tasks</a> namespace. You can use this task to create a route on Bing Maps from your app. In short terms this class has three important objects (2 properties / 1 method). It has a <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.bingmapsdirectionstask.start(v=VS.92).aspx" target="_blank">Start</a> and an <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.bingmapsdirectionstask.end(v=VS.92).aspx" target="_blank">End</a> property, and a method <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.bingmapsdirectionstask.show(v=VS.92).aspx" target="_blank">Show()</a> which is it.</p>
<p>Both properties are of type <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.labeledmaplocation(v=VS.92).aspx" target="_blank">LabeledMapLocation</a>, which have a constructor that expected a string for the name and <a href="http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinate(v=VS.92).aspx" target="_blank">GeoCoordinate</a> for the location.</p>
<p>
<p>In general below code will be enough to create a route on the Bing Maps app:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:fc6c9939-11e7-4641-b434-145c1ddd1450" class="wlWriterEditableSmartContent">
<pre style=" width: 614px; height: 111px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #000000;">BingMapsDirectionsTask directionTask </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> BingMapsDirectionsTask();
</span><span style="color: #008080;">2</span> <span style="color: #000000;">directionTask.Start </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> LabeledMapLocation(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Start</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> GeoCoordinate(</span><span style="color: #800080;">52.512794</span><span style="color: #000000;">, </span><span style="color: #800080;">6.091539</span><span style="color: #000000;">));
</span><span style="color: #008080;">3</span> <span style="color: #000000;">directionTask.End </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> LabeledMapLocation(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">End</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> GeoCoordinate(</span><span style="color: #800080;">52.512794</span><span style="color: #000000;">, </span><span style="color: #800080;">6.091539</span><span style="color: #000000;">));
</span><span style="color: #008080;">4</span> <span style="color: #000000;">
</span><span style="color: #008080;">5</span> <span style="color: #000000;">directionTask.Show();</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Just three lines of code. Can it be easier?</p>
<p>Yes it can!</p>
<p>If you don’t assign a value to the start property than it will automatically take your location and calculate a route to your End location.</p>
<p>I have created a sample solution where you can use the locations from the emulator to specify a start location and when you click on the map it will take your position (which is set by the emulator) and calculate a route to the location you have clicked.</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/07/BingMapsLocationChooser.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="BingMapsLocationChooser" border="0" alt="BingMapsLocationChooser" src="http://www.playingwith.net/wp-content/uploads/2011/07/BingMapsLocationChooser_thumb.png" width="464" height="364"></a></p>
<p><em>Choose a location by using the Additional tools.</em></p>
<p><em></em></p>
<p><em><a href="http://www.playingwith.net/wp-content/uploads/2011/07/BingMapsDirections.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="BingMapsDirections" border="0" alt="BingMapsDirections" src="http://www.playingwith.net/wp-content/uploads/2011/07/BingMapsDirections_thumb.png" width="133" height="246"></a></em></p>
<p><em>And there it is our own created direction in the Bing Maps app.</em></p>
<p><em></em></p>
<p>To be honest I’m a bit in doubt about what I think about this feature. On one side it’s a very handy, easily to implement feature that will give you navigation/routing to your location in minutes.</p>
<p>Another thought I still have is I’m adding a map control to my app, a user clicks around and if it needs to calculate a route it exits my app, and starts Bing Maps. No real integration.</p>
<p>Anyone having some thoughts about it?</p>
<p>Download:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:bb4571d7-f85d-4b19-a696-27ba4462beaf" class="wlWriterSmartContent">
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/07/BingMapsDirectionsTaskSample.zip" target="_blank">BingMapsDirectionsTaskSample.zip</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2011/07/integrate-bing-maps-directions-in-your-wp7-app/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated language support in Windows Phone 7 “Mango”</title>
		<link>http://www.playingwith.net/2011/07/updated-language-support-in-windows-phone-7-mango/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=updated-language-support-in-windows-phone-7-mango</link>
		<comments>http://www.playingwith.net/2011/07/updated-language-support-in-windows-phone-7-mango/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 19:18:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[dotnetmag]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[language support Windows phone 7]]></category>
		<category><![CDATA[Mango]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://chris-online.nl/?p=150</guid>
		<description><![CDATA[In the first release of Windows Phone 7 there was support for a few languages (English (US and UK), French, German, Italian, and Spanish.) With the Mango update Microsoft is adding 17 more languages: Brazilian Portuguese, Chinese (simplified and traditional), Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian (Bokmål), Polish, Portuguese, Russian, and Swedish. ...<p class="read-more"><a href="http://www.playingwith.net/2011/07/updated-language-support-in-windows-phone-7-mango/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>In the first release of Windows Phone 7 there was support for a few languages (English (US and UK), French, German, Italian, and Spanish.) With the Mango update Microsoft is adding 17 more languages: Brazilian Portuguese, Chinese (simplified and traditional), Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian (Bokmål), Polish, Portuguese, Russian, and Swedish.</p>
<p>&#160;</p>
<p>As I blogged earlier about the <a href="http://chris-online.nl/2010/12/windows-phone-7-directions-button-missing/" target="_blank">Windows Phone 7 directions button missing</a> and how to get your directions button back. This feature is with Mango updated with support in 19 countries. As you can see in below list of features and in which language it is supported, the “Local search results” or “Scout”&#160; as it is called either, will only be available (for now) in the Windows Phone 7 “Launch” countries. Note that if you set your <strong>browser &amp; search language</strong> to a non supported language than the “Scout” button will disappear from the Bing Maps menu bar.</p>
<p>&#160;</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/07/ScoutButton.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 6px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ScoutButton" border="0" alt="ScoutButton" align="left" src="http://www.playingwith.net/wp-content/uploads/2011/07/ScoutButton_thumb.png" width="39" height="39" /></a> &lt;= That’s the one you’re missing if you are setting the <strong>Browser &amp; Search language</strong> to a non <strong>Local search results</strong> country.</p>
<p>&#160;</p>
<ul>
<li><strong>Bing search</strong> (accessed from the phone’s hardware Search button) is available in 33 countries: Argentina, Australia, Austria, Belgium, Brazil, Canada, Denmark, Finland, France, Germany, Hong Kong, India, Indonesia, Ireland, Italy, Japan, Korea, Malaysia, Mexico, Netherlands, New Zealand, Norway, Philippines, Portugal, Russia, Singapore, South Africa, Spain, Sweden, Switzerland, Taiwan, United Kingdom, and the United States. (Elsewhere, handset and mobile operators can configure the hardware search button to a locally-relevant search site). </li>
<li><strong>Local search results</strong> show up in 6 countries: Australia, Canada, France, Germany, United Kingdom, and the United States. </li>
<li><strong>Maps</strong> is supported in 19 countries: Australia, Austria, Belgium, Brazil, Canada, Denmark, Finland, France, Germany, Italy, Netherlands, New Zealand, Portugal, Singapore, Spain, Sweden, Switzerland, United Kingdom, and the United States. </li>
<li><strong>Voice-to-text and Voice-to-dial</strong> is available in 6 countries: France, Germany, Italy, Spain, United Kingdom, and the Unites States. </li>
<li><strong>Voice search</strong> is supported in 4 countries: France, Germany, United Kingdom, and the United States. </li>
</ul>
<p>&#160;</p>
<p>One nice thing to mention about the language and region settings is that there are a lot of settings which in Mango don’t require your device to be restarted, but can be applied instant. That makes it easier to play around with these settings and find your own favorite.</p>
<p>&#160;</p>
<p><font size="1"><em>Language support source: </em></font></p>
<p><a href="http://www.everythingwm.com/microsoft-details-language-support-in-mango-update-for-windows-phone/2011/07/11/#more-4824"><font size="1"><em>http://www.everythingwm.com/microsoft-details-language-support-in-mango-update-for-windows-phone/2011/07/11/#more-4824</em></font></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2011/07/updated-language-support-in-windows-phone-7-mango/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the Func&lt;T&gt; delegate in .Net 3.5</title>
		<link>http://www.playingwith.net/2011/05/extending-the-funct-delegate-in-net-3-5/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extending-the-funct-delegate-in-net-3-5</link>
		<comments>http://www.playingwith.net/2011/05/extending-the-funct-delegate-in-net-3-5/#comments</comments>
		<pubDate>Mon, 23 May 2011 17:45:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Common]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[Extending]]></category>
		<category><![CDATA[Func]]></category>
		<category><![CDATA[System.Core]]></category>

		<guid isPermaLink="false">http://chris-online.nl/?p=140</guid>
		<description><![CDATA[Today I was working with the Func&#60;T&#62; delegate in my code. I was testing it at my local development machine in a .Net 4.0 console application. (Side information: I was trying to create a sort of overloaded methods which end up in a generic caching method, that has the ability to call the orginal method ...<p class="read-more"><a href="http://www.playingwith.net/2011/05/extending-the-funct-delegate-in-net-3-5/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Today I was working with the <a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx" target="_blank">Func&lt;T&gt;</a> delegate in my code. I was testing it at my local development machine in a .Net 4.0 console application. (Side information: I was trying to create a sort of overloaded methods which end up in a generic caching method, that has the ability to call the orginal method to get data when there is no data found in the cache.)</p>
<p>My data method has five arguments in the signature and I was writing the following methods:</p>
<p><strong>Generic caching method:</strong></p>
<pre style="width: 617px; height: 210px" class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">static</span> TResult PerformCaching&lt;TResult&gt;(Func&lt;TResult&gt; func, <span class="kwrd">string</span> cacheKey)
{
    var cachedData = Get&lt;<span class="kwrd">object</span>&gt;(cacheKey); <span class="rem">// &lt;= check if there is data in the cache. </span>

    <span class="kwrd">if</span> (cachedData == <span class="kwrd">null</span>)
    {
        <span class="kwrd">return</span> func.Invoke(); <span class="rem">// &lt;= if not invoke the delegate. </span>
    }

    <span class="kwrd">return</span> (TResult)cachedData;
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><strong>Public caching method:</strong></p>
<pre style="width: 606px; height: 97px" class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> TResult PerformCaching&lt;TResult, T1, T2, T3, T4, T5&gt;(Func&lt;T1, T2, T3, T4, T5, TResult&gt; func, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, <span class="kwrd">string</span> cacheKey)
{
    <span class="kwrd">return</span> PerformCaching(() =&gt; func(arg1, arg2, arg3, arg4, arg5), cacheKey);
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&nbsp;</p>
<p>Running this in my .Net 4.0 console application works like a charm. However when I tried to implement this in our SharePoint 2010 project, which is running .Net 3.5 it’s giving me an error in my Error console:</p>
<p><font color="#ff0000"><strong>Using the generic type &#8216;System.Func&lt;TResult&gt;&#8217; requires 1 type arguments</strong></font></p>
<p>Ok, time to grab reflector and see what’s happening under the hood: I have loaded the .Net 3.5 System.Core.dll manually. (In my case Reflector is starting up with default .Net 4.0) I see the following:</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/05/SystemCoreNet35.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SystemCoreNet35" border="0" alt="SystemCoreNet35" src="http://www.playingwith.net/wp-content/uploads/2011/05/SystemCoreNet35_thumb.png" width="264" height="323"></a></p>
<p>Both <a href="http://msdn.microsoft.com/en-us/library/018hxwa8.aspx" target="_blank">Action&lt;T&gt;</a> and <a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx" target="_blank">Func&lt;T&gt;</a> have a maximum support for four generic arguments in .Net 3.5.</p>
<p>&nbsp;</p>
<p>Okay, let’s compare this to .Net 4.0 where my example with five arguments is working like a charm.</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/05/SystemCoreNet40.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SystemCoreNet40" border="0" alt="SystemCoreNet40" src="http://www.playingwith.net/wp-content/uploads/2011/05/SystemCoreNet40_thumb.png" width="436" height="368"></a></p>
<p>&nbsp;</p>
<p>From .Net 4.0 on there is support for 16 generic parameters in your Func&lt;T&gt; delegate. Ok, very nice this support in .Net 4.0, but SharePoint 2010 is still running .Net 3.5 and probably will not be updated to .Net 4.0. How can we fix this issue in .Net 3.5?</p>
<p>Well, that will be very easily been fixed with one line of code <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Emoticon met brede lach" src="http://www.playingwith.net/wp-content/uploads/2011/05/wlEmoticon-openmouthedsmile.png">.</p>
<p>In our code we add ourselves a Func&lt;T&gt; delegate with the five needed generic arguments like below:</p>
<pre style="width: 617px; height: 41px" class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">delegate</span> TResult Func&lt;T1, T2, T3, T4, T5, TResult&gt;(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); </pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now you can compile your .Net 3.5 project and it’s supporting this five arguments Func&lt;T&gt; delegate. Now say how easy was that?</p>
<p>One of the issues that interests me is the part that when I look into the .Net 4.0 System.Core DLL, the Func&lt;T&gt; delegate starts with Func&lt;T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult&gt; and not with Func&lt;T1, TResult&gt;. I tried to found out where the other Func&lt;T&gt;’s have gone, and found out that these have a <a href="http://msdn.microsoft.com/en-us/library/ms404275.aspx" target="_blank">TypeForwardedFrom</a> attribute like below:</p>
<pre style="width: 620px; height: 38px" class="csharpcode">[TypeForwardedFrom(<span class="str">"System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089"</span>)]</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>The link gives the explanation I think very clear <em>`Type forwarding allows you to move a type to another assembly without having to recompile applications that use the original assembly.`</em></p>
<p><em></em></p>
<p>Well that´s it about extending the Func&lt;T&gt; delegate, hope it will be helpful for you. If you have any questions or remarks please let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2011/05/extending-the-funct-delegate-in-net-3-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting your Enterprise Library performance counters to work.</title>
		<link>http://www.playingwith.net/2011/05/getting-your-enterprise-library-performance-counters-to-work/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-your-enterprise-library-performance-counters-to-work</link>
		<comments>http://www.playingwith.net/2011/05/getting-your-enterprise-library-performance-counters-to-work/#comments</comments>
		<pubDate>Sat, 14 May 2011 18:07:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Enterprise Library]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Enterprise Library 5.0]]></category>
		<category><![CDATA[Performance Counters]]></category>
		<category><![CDATA[Performance monitor]]></category>

		<guid isPermaLink="false">http://chris-online.nl/?p=133</guid>
		<description><![CDATA[This week I have been extensively been working with Enterprise Library 5.0 .(Also called as EntLib) In most of the cases Enterprise Library works in the background and it is not always that clear about what’s happening under the hood. Well, this applied for me either this week. I&#8217;m using the Caching Application Block of ...<p class="read-more"><a href="http://www.playingwith.net/2011/05/getting-your-enterprise-library-performance-counters-to-work/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>This week I have been extensively been working with <a href="http://entlib.codeplex.com/" target="_blank">Enterprise Library 5.0</a> .(Also called as EntLib) In most of the cases Enterprise Library works in the background and it is not always that clear about what’s happening under the hood. Well, this applied for me either this week. I&#8217;m using the <a href="http://msdn.microsoft.com/en-us/library/ff649551.aspx" target="_blank">Caching Application Block</a> of Entlib and was curious about how this performed (how many items are there in the cache list, how many expirations occur, are expired items removed etc.)</p>
<p>First step I took was installing the EntLib instrumentation which can be installed by executing<sup>1</sup> a .bat file which comes with the installation of Entlib.</p>
<p><sup>1 </sup><em>Note that executing this batch file should be done with administrator privileges.</em></p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/05/InstallInstrumentation.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="InstallInstrumentation" border="0" alt="InstallInstrumentation" src="http://www.playingwith.net/wp-content/uploads/2011/05/InstallInstrumentation_thumb.png" width="271" height="340"></a></p>
<p>&nbsp;</p>
<p>Actually I thought that this was it. All that I had to do was adding the counters in performance monitor (PerfMon) and see what happing under the hood. When I was trying to add the counters to PerfMon, I saw that the instrumentation installation has succeeded, because the counters where there.</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/05/EntLibPerformanceCounters.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="EntLibPerformanceCounters" border="0" alt="EntLibPerformanceCounters" src="http://www.playingwith.net/wp-content/uploads/2011/05/EntLibPerformanceCounters_thumb.png" width="469" height="362"></a></p>
<p>&nbsp;</p>
<p>But adding the counters was not possible. After some searches on the internet I found out that you have to enable performance counters in your application before you can add them to PerfMon to see what’s going on down there.</p>
<p>There are two ways of enabling your application to use performance counters. One is by using the configuration tool which is shipped with EntLib, or manually update your .config file with some references to EntLib dll’s and adding a configuration section. I’ll start with the first one, which is the easiest and is doing the adding part to the .config file for you.</p>
<p><strong>Updating the .config file by use of the EntLib tool:</strong></p>
<p>Start the EntLib configuration tool (Can be found under: All programs =&gt; Microsoft patterns &amp; practices =&gt; Enterprise Library 5.0 =&gt; Enterprise Library Configuration) that fits to the .Net framework you’re using in your application. In my case that will be the X86 .Net 4.0 framework.</p>
<p>When the configuration tool is loaded, choose File =&gt; Open, navigate to your .config file and open it. Once it is opened, choose Blocks =&gt; Add Instrumentation Settings</p>
<p><a href="http://www.playingwith.net/wp-content/uploads/2011/05/AddInstrumentationSettings.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="AddInstrumentationSettings" border="0" alt="AddInstrumentationSettings" src="http://www.playingwith.net/wp-content/uploads/2011/05/AddInstrumentationSettings_thumb.png" width="280" height="360"></a></p>
<p>&nbsp;</p>
<p>Expand the Instrumentation settings block and set performanceCountersEnabled to true. Save the settings, so they will be written to your .config file. If you restart your application after saving, and then try to add a performance counter again, you will see that your process is added to the list of instances and that you’re able to add the counters.</p>
<p>&nbsp;</p>
<p><strong>Updating the .config file manually:</strong></p>
<p>I can imagine that if you’re in the situation that you don’t have the configuration tool available to adjust your .config file (Like me on the production environment) you want to insert these settings manually. Below I will show you how and where to enter these settings in your config file to make this work.</p>
<p>The first step will be to open your .config file in your favorite (or the available) editor.</p>
<p>Now we have to add two parts to the config file. First one is the reference to EntLib to make sure the compiler knows what you mean when you say that you would like to enable the performance counters.</p>
<p>We do that by adding a new <a href="http://msdn.microsoft.com/en-us/library/ms228256.aspx" target="_blank">ConfigSection</a>. Within this configsection we add a section where we reference the EntLib 5.0 resources like below.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:05e3bc5e-9fbc-4345-bf3e-24f0ebab4609" class="wlWriterEditableSmartContent">
<pre style=" width: 614px; height: 111px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">&lt;</span><span style="color: #800000;">configSections</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">2</span> <span style="color: #000000;">   </span><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">section </span><span style="color: #FF0000;">name</span><span style="color: #0000FF;">=&quot;instrumentationConfiguration&quot;</span><span style="color: #FF0000;">
</span><span style="color: #008080;">3</span> <span style="color: #FF0000;">            type</span><span style="color: #0000FF;">=&quot;Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration.InstrumentationConfigurationSection,
</span><span style="color: #008080;">4</span> <span style="color: #0000FF;">                  Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;</span><span style="color: #FF0000;">
</span><span style="color: #008080;">5</span> <span style="color: #FF0000;">            requirePermission</span><span style="color: #0000FF;">=&quot;true&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;">6</span> <span style="color: #000000;"> </span><span style="color: #0000FF;">&lt;/</span><span style="color: #800000;">configSections</span><span style="color: #0000FF;">&gt;</span><span style="color: #000000;"> </span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>The second part is setting the performance counters to enabled, which can be done with below code:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:6d4fb787-e055-43b5-b21d-11f065f34628" class="wlWriterEditableSmartContent">
<pre style=" width: 567px; height: 52px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">&lt;</span><span style="color: #800000;">instrumentationConfiguration </span><span style="color: #FF0000;">performanceCountersEnabled</span><span style="color: #0000FF;">=&quot;true&quot;</span><span style="color: #FF0000;"> </span><span style="color: #0000FF;">/&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>That is it! Pretty easy as you know how and where to configure it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2011/05/getting-your-enterprise-library-performance-counters-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using HttpServerUtility.Transfer with IHttpHandler</title>
		<link>http://www.playingwith.net/2011/03/using-httpserverutility-transfer-with-ihttphandler/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-httpserverutility-transfer-with-ihttphandler</link>
		<comments>http://www.playingwith.net/2011/03/using-httpserverutility-transfer-with-ihttphandler/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 06:36:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[HttpContext]]></category>
		<category><![CDATA[HttpContext.Items]]></category>
		<category><![CDATA[HttpServerUtility.Transer]]></category>
		<category><![CDATA[IHttpHandler]]></category>
		<category><![CDATA[OnPreRender]]></category>
		<category><![CDATA[Page]]></category>
		<category><![CDATA[Page_Load]]></category>
		<category><![CDATA[ProcessRequest]]></category>
		<category><![CDATA[Reflector]]></category>
		<category><![CDATA[Server.Transfer]]></category>

		<guid isPermaLink="false">http://chris-online.nl/?p=102</guid>
		<description><![CDATA[Last week I was working on some kind of lightweight downloadhandler where i could pass some information from one page to the downloadhandler by using the HttpContext.Items collection. To be able to use the HttpContext.Items collection on the downloadhandler, I have to use the HttpServerUtility.Transfer() method (details can found at MSDN), which sends the HttpContext ...<p class="read-more"><a href="http://www.playingwith.net/2011/03/using-httpserverutility-transfer-with-ihttphandler/">>>Read more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Last week I was working on some kind of lightweight downloadhandler where i could pass some information from one page to the downloadhandler by using the HttpContext.Items collection. </p>
<p>To be able to use the HttpContext.Items collection on the downloadhandler, I have to use the <a href="http://msdn.microsoft.com/en-us/library/y0w8173d(v=VS.80).aspx" target="_blank">HttpServerUtility.Transfer()</a> method (details can found at <a href="http://msdn.microsoft.com/en-us/library/8z9e2zxx(v=vs.80).aspx" target="_blank">MSDN</a>), which sends the HttpContext to the page we’re transferring to. When looking at <a href="http://msdn.microsoft.com/en-us/library/8z9e2zxx(v=VS.80).aspx" target="_blank">MSDN</a>, I found out that there is an overload for <a href="http://msdn.microsoft.com/en-us/library/8z9e2zxx(v=VS.80).aspx" target="_blank">HttpServerUtility.Transfer(IHttpHandler, Boolean)</a> which takes <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx" target="_blank">IHttpHandler</a> and a Boolean as parameters.</p>
<p>Nice…. at least that’s what I thought then. There wasn’t that many documentation about using this overload, so I gave it a try.&nbsp;&nbsp; First I created my DownloadHandler as below:&nbsp; </p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> DownloadHandler : IHttpHandler
{
    <span class="kwrd">public</span> <span class="kwrd">bool</span> IsReusable
    {
        get { <span class="kwrd">return</span> <span class="kwrd">false</span>; }
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> ProcessRequest(HttpContext context)
    {
        var content = context.Items[<span class="str">"Content"</span>].ToString();
        var fileType = context.Items[<span class="str">"FileType"</span>].ToString();
        var fileName = <span class="str">"CSV_"</span> + DateTime.Now.ToString() + fileType;

        context.Response.ClearHeaders();
        context.Response.ClearContent();
        context.Response.Clear();
        context.Response.ContentType = <span class="str">"application/ms-excel"</span>;
        context.Response.AddHeader(<span class="str">"content-disposition"</span>, <span class="str">"inline;filename="</span> + fileName);

        context.Response.Write(content);
        context.Response.End();

    }
}</pre>
<p>And from my webpage did a call to HttpServerUtility.Transfer() like below:</p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
{
    Context.Items.Add(<span class="str">"Content"</span>, <span class="str">"colum1;column2;column3"</span>);
    Context.Items.Add(<span class="str">"FileType"</span>, <span class="str">".csv"</span>);

    DownloadHandler handler = <span class="kwrd">new</span> DownloadHandler();
    Server.Transfer(handler, <span class="kwrd">true</span>);
}</pre>
<p>I run the project and BOOM:</p>
<p><i><font color="#ff0000" size="3">Error executing child request for handler </font></i><i><font color="#ff0000" size="3">&#8216;</font></i><i><font color="#ff0000" size="3">WebApplication3.DownloadHandler&#8217;.</font></i><em></p>
<p></em><br />Initial I thought that it was the Boolean parameter which is causing the ViewState to be preserved and when calling the handler that would be indicated by IIS as not valid for this page. Setting the Boolean to false resulted in the same error.</p>
<p>I searched a bit on Google but couldn’t find a good answer why this was not working. So I used <a href="http://www.reflector.net/" target="_blank">Reflector</a> to check the .Net assembly to see what’s happening in that Transfer() method. (HttpServerUtility can be found in the System.Web dll.) And to my surprise I saw the following code within that method:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Transfer(IHttpHandler handler, <span class="kwrd">bool</span> preserveForm)
{
    Page page = handler <span class="kwrd">as</span> Page;
    <span class="kwrd">if</span> ((page != <span class="kwrd">null</span>) &amp;&amp; page.IsCallback)
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(SR.GetString(<span class="str">"Transfer_not_allowed_in_callback"</span>));
    }
    <span class="kwrd">this</span>.Execute(handler, <span class="kwrd">null</span>, preserveForm);
    <span class="kwrd">this</span>._context.Response.End();
}</pre>
<p>If the handler is not of type <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.aspx" target="_blank">Page</a> than it will definitly be null. That’s what exactly is happening in my case. Second thought about it is that if handler could be of type Page, than Page will implement IHttpHandler. Let’s have a look at the Page class in Reflector. (Page can be found in System.Web.UI dll.) And there it is:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Page : TemplateControl, IHttpHandler
{
}</pre>
<p>And our implementation of the ProcessRequest method:</p>
<pre class="csharpcode">[EditorBrowsable(EditorBrowsableState.Never)]
<span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> ProcessRequest(HttpContext context)
{
    <span class="kwrd">if</span> ((HttpRuntime.NamedPermissionSet != <span class="kwrd">null</span>)           !HttpRuntime.DisableProcessRequestInApplicationTrust)
    {
        <span class="kwrd">if</span> (!HttpRuntime.ProcessRequestInApplicationTrust)
        {
            <span class="kwrd">this</span>.ProcessRequestWithAssert(context);
            <span class="kwrd">return</span>;
        }
        <span class="kwrd">if</span> (<span class="kwrd">base</span>.NoCompile)
        {
            HttpRuntime.NamedPermissionSet.PermitOnly();
        }
    }
    <span class="kwrd">this</span>.ProcessRequestWithNoAssert(context);
}
</pre>
<p>As you can see <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.processrequest.aspx" target="_blank">ProcessRequest</a> is virtual, so we can override it with our own implementation. With this information I updated my DownloadHandler class to derive from Page instead of direct from IHttpHandler and override the ProcessRequest method. The DownloadHandler class will look like below:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> DownloadHandler : Page
{
    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> ProcessRequest(HttpContext context)
    {
        var content = context.Items[<span class="str">"Content"</span>].ToString();
        var fileType = context.Items[<span class="str">"FileType"</span>].ToString();
        var fileName = <span class="str">"CSV_"</span> + DateTime.Now.ToString() + fileType;

        context.Response.ClearHeaders();
        context.Response.ClearContent();
        context.Response.Clear();
        context.Response.ContentType = <span class="str">"application/ms-excel"</span>;
        context.Response.AddHeader(<span class="str">"content-disposition"</span>, <span class="str">"inline;filename="</span> + fileName);

        context.Response.Write(content);
        context.Response.End();
    }
}</pre>
<p>When running this code the file is outputted to the browser and after that the request is ended. I have added also the <a href="http://msdn.microsoft.com/en-US/library/system.web.ui.control.load(v=VS.80).aspx" target="_blank">Page_Load</a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.prerender(v=VS.80).aspx" target="_blank">OnPreRender</a> events, but there not executed in this sample. That’s a good thing, because right now we have our lightweight downloadhandler which is working in a very early stage of the Page lifecycle. (Actually it’s happening before the page lifecycle.)Well, I hope that this will help someone who is also trying to use this overload and is facing the same issues with the implementation. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.playingwith.net/2011/03/using-httpserverutility-transfer-with-ihttphandler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

