<?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>Frederik Vig - ASP.NET developer &#187; ASP.NET</title>
	<atom:link href="http://www.frederikvig.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederikvig.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Dec 2011 23:33:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Faster EPiServer sites &#8211; client side performance</title>
		<link>http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=faster-episerver-sites-client-side-performance</link>
		<comments>http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 08:59:04 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Scaling]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1681</guid>
		<description><![CDATA[First part of a new series where I&#8217;m going to focus on performance and scaling. I&#8217;m going to go through all the best practices we as EPiServer developers should know about, not only to create EPiServer sites that are fast, but ultra-fast. I&#8217;m going to use the Overlook hotel sample site. The goal is of ...]]></description>
			<content:encoded><![CDATA[<p>First part of a new series where I&#8217;m going to focus on performance and scaling. I&#8217;m going to go through all the best practices we as EPiServer developers should know about, not only to create EPiServer sites that are fast, but ultra-fast.</p>
<p>I&#8217;m going to use the <a href="http://world.episerver.com/Download/Items/EPiServer-CMS/EPiServer-CMS-6-R2/EPiServer-Overlook-R2-Demo-Site/">Overlook hotel sample site</a>. The goal is of course to make it ultra-fast!</p>
<p>To follow along you should have the overlook site installed and setup. Let&#8217;s get started!</p>
<h2>Client side performance</h2>
<p>I&#8217;m using Firefox as my main developer browser, I&#8217;ll also be using three great addons for Firefox: <a href="http://getfirebug.com/">Firebug</a>, <a href="http://developer.yahoo.com/yslow/">YSlow</a>, and <a href="http://code.google.com/speed/page-speed/">Page Speed</a>.</p>
<p>If we run YSlow on the front page of overlook hotel we&#8217;ll get a score of 66/100 (grade D) with a few suggestions for improvements.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/yslow-before.png" alt="YSlow - EPiServer Overlook Hotel demo site before" />
</p>
<p>With Page Speed we get a score of 62/100.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/page-speed-before.png" alt="Page Speed - EPiServer Overlook Hotel demo site before" />
</p>
<p>I&#8217;m going to focus on IIS 7 and above, most of the stuff is also possible with IIS 6, but I&#8217;m not going to go through IIS 6.</p>
<h3>Compress components with gzip</h3>
<p>Read more about the benefits of gzipping your content here: <a href="http://developer.yahoo.com/performance/rules.html#gzip">Gzip Components</a>. </p>
<p>In IIS 7 this is very easy. First make sure you have both static and dynamic compression installed.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/gzip-compression-iis-features.png" alt="Install Static and Dynamic compression features in IIS 7" />
</p>
<p>Next step is enabling both static and dynamic compression in web.config. Go to the &lt;system.webServer&gt; section and add the following:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;urlCompression</span> <span style="color: #000066;">doDynamicCompression</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">doStaticCompression</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">dynamicCompressionBeforeCache</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>Re-run both YSlow and Page Speed. Your score should now be 72 and 78 with an A in gzip.</p>
<p>You can find more information on <a href="http://www.iis.net/ConfigReference/system.webServer/urlCompression">urlCompression on IIS.NET</a>. By default IIS 7 will actually enable static and dynamic compression for you.</p>
<p>You might have spotted the httpCompression section under &lt;system.webServer&gt;.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;httpCompression<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;text/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;message/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/x-javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;*/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dynamicTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;text/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;message/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/x-javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;*/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dynamicTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;gzip&quot;</span> <span style="color: #000066;">dll</span>=<span style="color: #ff0000;">&quot;%Windir%\system32\inetsrv\gzip.dll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpCompression<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>You don&#8217;t actually need this section to enable gzip (IIS will just use it&#8217;s default settings), but it&#8217;s nice to know about it when you need to tweak your default gzip settings a bit. Basically urlCompression specifies what to compress and httpCompression specifies how. More information on httpCompression: <a href="http://www.iis.net/ConfigReference/system.webServer/httpCompression">HTTP Compression &lt;httpCompression&gt;</a>.</p>
<p>If we check the applicationHost.config file for IIS 7 you can see the default settings (location: %windir%\system32\inetsrv\config\applicationHost.config):</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>httpCompression directory<span style="color: #008000;">=</span><span style="color: #666666;">&quot;%SystemDrive%<span style="color: #008080; font-weight: bold;">\i</span>netpub<span style="color: #008080; font-weight: bold;">\t</span>emp<span style="color: #008080; font-weight: bold;">\I</span>IS Temporary Compressed Files&quot;</span><span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>scheme name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;gzip&quot;</span> dll<span style="color: #008000;">=</span><span style="color: #666666;">&quot;%Windir%<span style="color: #008080; font-weight: bold;">\s</span>ystem32<span style="color: #008080; font-weight: bold;">\i</span>netsrv<span style="color: #008080; font-weight: bold;">\g</span>zip.dll&quot;</span> <span style="color: #008000;">/&gt;</span>
	<span style="color: #008000;">&lt;</span>staticTypes<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;message/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/x-javascript&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/atom+xml&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/xaml+xml&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;*/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> <span style="color: #008000;">/&gt;</span>
	<span style="color: #008000;">&lt;/</span>staticTypes<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>dynamicTypes<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;message/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/x-javascript&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;*/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> <span style="color: #008000;">/&gt;</span>
	<span style="color: #008000;">&lt;/</span>dynamicTypes<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>httpCompression<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>By default httpCompression is set to only gzip files over 2700 bytes, we can fix this by adding the following code:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;httpCompression</span> <span style="color: #000066;">directory</span>=<span style="color: #ff0000;">&quot;%SystemDrive%\websites\_compressed&quot;</span> <span style="color: #000066;">minFileSizeForComp</span>=<span style="color: #ff0000;">&quot;1024&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;gzip&quot;</span> <span style="color: #000066;">dll</span>=<span style="color: #ff0000;">&quot;%Windir%\system32\inetsrv\gzip.dll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;text/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;message/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/json&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;*/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpCompression<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<h3>Add Expires headers</h3>
<p>Adding Expires headers to static and dynamic files like CSS, JavaScript and images tells the client to cache the files locally, lessening the burden on the server (less requests). Making your sites resources/components cache-able. More information: <a href="developer.yahoo.com/performance/rules.html#expires">Add an Expires or a Cache-Control Header</a>.</p>
<p>Back in our sites web.config file under the &lt;system.webServer&gt; section, we have the &lt;staticContent&gt; section:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseMaxAge&quot;</span> <span style="color: #000066;">cacheControlMaxAge</span>=<span style="color: #ff0000;">&quot;1.00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/clientCache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>The interesting part here is of course the <a href="http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache">clientCache element</a>. </p>
<p>UseMaxAge will add CacheControlMaxAge to the HTTP Headers sent to the client, we can then tell the client to cache the static files for 1 year:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseMaxAge&quot;</span> <span style="color: #000066;">cacheControlMaxAge</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>With UseExpires you specify a date instead:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseExpires&quot;</span> <span style="color: #000066;">httpExpires</span>=<span style="color: #ff0000;">&quot;Tue, 19 Jan 2038 03:14:07 GMT&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>You can only use one of these (if you&#8217;re not using the location element) at a time. I usually use MaxAge, it&#8217;s simpler and you don&#8217;t have to remember to update your settings when the date passes. </p>
<p>The important thing to remember is that if you make any changes to the static files you&#8217;ll need to use another name. You can add a querystring, change the name, or in some other way update the path to reflect that the file has changed.</p>
<p>Let&#8217;s update it to say that the client should cache the files for 1 year:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseMaxAge&quot;</span> <span style="color: #000066;">cacheControlMaxAge</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>This helped bring the list of components down from 86 to 15. But we&#8217;re not quite finished yet.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/expires-headers-yslow1.png" alt="Down from 86 to 15 files in YSlow Add Expires headers" />
</p>
<p>EPiServer uses the location element to specify access rights and to use EPiServer&#8217;s StaticFileHandler for files located in Global Files, Page Files, Documents and other places that use Virtual Path Providers.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;PageFiles&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webresources&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;WebResource.axd&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;GET&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Handlers.AssemblyResourceLoader&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wildcard&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Web.StaticFileHandler, EPiServer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticFile</span> <span style="color: #000066;">expirationTime</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;Documents&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webresources&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;WebResource.axd&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;GET&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Handlers.AssemblyResourceLoader&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wildcard&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Web.StaticFileHandler, EPiServer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticFile</span> <span style="color: #000066;">expirationTime</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;Global&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webresources&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;WebResource.axd&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;GET&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Handlers.AssemblyResourceLoader&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wildcard&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Web.StaticFileHandler, EPiServer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticFile</span> <span style="color: #000066;">expirationTime</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>More information in EPiServer&#8217;s SDK: <a href="http://sdk.episerver.com/library/cms6/Developers%20Guide/Advanced%20Features/Caching/StaticFileCaching.htm">Caching of static files</a>. This technique uses the Expires header instead of MaxAge, but with the same effect.</p>
<p>You might have noticed the &lt;caching&gt; section:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;caching<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.gif&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.png&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.js&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.css&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.jpg&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.jpeg&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>The caching setting is used to configure output caching for IIS. You have both output caching for IIS and for ASP.NET. More information: <a href="http://www.iis.net/ConfigReference/system.webServer/caching">Caching &lt;caching&gt;</a>. By default IIS output caching is turned on. </p>
<p>What EPiServer has done is told IIS to not cache static files like images, CSS and JavaScript and let ASP.NET handle it instead. You can read more about IIS output caching here: <a href="http://learn.iis.net/page.aspx/710/configure-iis-7-output-caching/">Configure IIS 7 Output Caching</a>.</p>
<p>Let&#8217;s remove the whole &lt;caching&gt; section and use the default settings instead. </p>
<p>Now we have a score of 78 points in YSlow and 95 in Page Speed. Here you can see how much of the total size is now cached:</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/yslow-cache.png" alt="YSlow showing the pages local cache" />
</p>
<p>On the left we can see the total size and number of requests the first time, on the right is the size and number of requests after that. We&#8217;re now down to 3 requests and 16KB. Quite an improvement don&#8217;t you think?</p>
<h3>Minify JavaScript and CSS</h3>
<p>When we&#8217;re developing we usually work with multiple JavaScript and CSS files to make it easier to structure and maintain them. However in production we should take care to automatically compress and bundle the files.</p>
<p>It&#8217;s important to note the difference between the rule <a href="http://developer.yahoo.com/performance/rules.html#gzip">Gzip Components</a> and <a href="http://developer.yahoo.com/performance/rules.html#minify">Minify JavaScript and CSS</a>, which will remove comments, unneeded whitespaces and replace variable/function names with shorter versions.</p>
<p>There are a few tools we can use for this:</p>
<ul>
<li><a href="http://nuget.org/List/Packages/SquishIt">SquishIt</a> &#8211; I&#8217;ve written about it before: <a href="http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/">CSS and JavaScript compression and bundling</a></li>
<li><a href="http://nuget.org/List/Packages/Cassette.Web">Cassette</a></li>
<li><a href="http://nuget.org/List/Packages/Microsoft.Web.Optimization">ASP.NET 4.5 Optimization</a></li>
</ul>
<p>We&#8217;re going to use ASP.NET 4.5 Optimization preview. You can easily install it through NuGet. </p>
<p>Note: you&#8217;ll need to run .NET 4, so we&#8217;ll need to upgrade our solution to use .NET 4 instead of .NET 3.5. This is quite easy thanks to <a href="http://twitter.com/davidknipeta">David Knipe</a>. Change the projects target framework in Visual Studio and install the EPiServerCMS6ToNetFour package from <a href="http://nuget.episerver.com">nuget.episerver.com</a>.</p>
<p>After that you&#8217;ll be able to install ASP.NET 4.5 Optimization successfully. </p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/nuget-asp-net-optimization.png" alt="ASP.NET 4.5 Optimization installation with NuGet in Visual Studio 2010" />
</p>
<p>To enable it we just call the EnableDefaultBundles() method inside Application_Start in Global.asax:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Global <span style="color: #008000;">:</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Global</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		BundleTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Bundles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EnableDefaultBundles</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>Next step is updating the way external JavaScript and CSS files are included. By default, everything you refer to in a folder gets bundled together (only for the same type, so JavaScript and CSS files don&#8217;t get bundled together even if they&#8217;re in the same folder).</p>
<div class="wp_syntax">
<div class="code">
<pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Templates/DemoSite/Styles/Main/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Templates/DemoSite/Scripts/Main/js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre>
</div>
</div>
<p>We add the path to the folder followed by either /css or /js.</p>
<p>I had to manually update the code-behind files of site.master and the composer functions and change:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterCSSFile</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ComposerFunctions.Teaser.Styles.Teaser.css&quot;</span>, UriSupport<span style="color: #008000;">.</span><span style="color: #0000FF;">ResolveUrlBySettings</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Templates/DemoSite/ComposerFunctions/Teaser/Styles/Teaser.css&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>To:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterCSSFile</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ComposerFunctions.Teaser.Styles.Teaser.css&quot;</span>, UriSupport<span style="color: #008000;">.</span><span style="color: #0000FF;">ResolveUrlBySettings</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Templates/DemoSite/ComposerFunctions/Teaser/Styles/css&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>What I did was bundle the different JavaScript and CSS files into folders like components/modules and updated their references to use these folders instead.</p>
<p>There were a few inline scripts that I didn&#8217;t compress, but overall this helped a lot. I have now 97/100 points in Page Speed and 79/100 in YSlow.</p>
<h3>Make fewer HTTP requests</h3>
<p>Modern browsers can send up-to 6 requests at a time to the same domain. Older browsers up-to 2. Combining resource files like JavaScript, CSS and images into as few files as possible not only decreases the sites total size, but also make it load much faster for the client.</p>
<p>For JavaScript and CSS files we can use the technique we learned in the previous step (Minify JavaScript and CSS). For images we can use CSS sprites or embed the images.</p>
<p>What we&#8217;re going to do is embed the CSS background images into the stylsheets. I&#8217;ve borrowed the code from Mads Kristensen&#8217;s presentation on <a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-837T">Build &#8211; Optimize your website using ASP.NET and IIS8</a>.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Hosting</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Web.Optimization</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> CssWithImagesMinify <span style="color: #008000;">:</span> CssMinify
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Regex url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;url\((([^\)]*)\?embed)\)&quot;</span>, RegexOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Singleline</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> format <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;url(data:image/{0};base64,{1})&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Process<span style="color: #008000;">&#40;</span>BundleResponse bundle<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetLastModifiedFromFileDependencies</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Process</span><span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> reference <span style="color: #008000;">=</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/css&quot;</span>, <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// When publishing the bundler can be called from &quot;/&quot; causing image reference to be invalid.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>reference <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span>
                reference <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/Content/&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Match match <span style="color: #0600FF; font-weight: bold;">in</span> url<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                var file <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileInfo<span style="color: #008000;">&#40;</span>HostingEnvironment<span style="color: #008000;">.</span><span style="color: #0000FF;">MapPath</span><span style="color: #008000;">&#40;</span>reference <span style="color: #008000;">+</span> match<span style="color: #008000;">.</span><span style="color: #0000FF;">Groups</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #6666cc; font-weight: bold;">string</span> dataUri <span style="color: #008000;">=</span> GetDataUri<span style="color: #008000;">&#40;</span>file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span> <span style="color: #008000;">=</span> bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span>match<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>, dataUri<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddFileDependency</span><span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetDataUri<span style="color: #008000;">&#40;</span>FileInfo file<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> buffer <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadAllBytes</span><span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> ext <span style="color: #008000;">=</span> file<span style="color: #008000;">.</span><span style="color: #0000FF;">Extension</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>format, ext, Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToBase64String</span><span style="color: #008000;">&#40;</span>buffer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>For all the images we want to embed we just add ?embed behind their name:</p>
<div class="wp_syntax">
<div class="code">
<pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../Images/abuse.png?embed'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span></pre>
</div>
</div>
<p>We also need to update Global.asax and tell BundleTable to use our CSS Minifier instead.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	var css <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DynamicFolderBundle<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;css&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>CssWithImagesMinify<span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;*.css&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	var js <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DynamicFolderBundle<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;js&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>JsMinify<span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;*.js&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	BundleTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Bundles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>css<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	BundleTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Bundles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>js<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>The CSS files now have their background images embedded automatically!</p>
<div class="wp_syntax">
<div class="code">
<pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5IAAAAFCAYAAAA3+tN0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGFJREFUeNrs1zEKg1AQRdE/VgYN4uZcZDYXxEDSfd8W0gmeA5fpp3vVWpvSmB5pTs+0pLX3/moAAADcTlVtOe+0pyN90jf9Bu8BAADgH4YkAAAAhiQAAACGJAAAABdxCjAAa0EKFYXT/VsAAAAASUVORK5CYII=&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-y</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span></pre>
</div>
</div>
<p>There&#8217;s also a nice extension for Visual Studio that let&#8217;s right-click a folder inside Visual Studio and optimize all the images inside that folder: <a href="http://visualstudiogallery.msdn.microsoft.com/a56eddd3-d79b-48ac-8c8f-2db06ade77c3">Image Optimizer</a>.</p>
<p>I now have 99/100 in Page Speed and 95/100 in YSlow.</p>
<h3>Further improvements</h3>
<ul>
<li>Use a CDN &#8211; See <a href="http://developer.yahoo.com/performance/rules.html#cdn">Use a Content Delivery Network</a> and <a href="http://world.episerver.com/Blogs/Andre-Brynildsen/Dates/2011/9/Virtual-Path-Provider-for-Amazon-S3/">Virtual Path Provider for Amazon S3</a></li>
<li>Remove whitespaces and comments from HTML markup</li>
<li>Optimize CSS selectors and placement of stylesheets</li>
<li>Optimize JavaScript code, especially jQuery, remove inline code and update the placement of the JavaScript code</li>
<li><a href="http://developer.yahoo.com/performance/rules.html#dns_lookups">Reduce DNS Lookups</a> and consider using a service like <a href="http://aws.amazon.com/route53/">Amazon&#8217;s Route 53</a> for faster DNS lookups</li>
</ul>
<h3>Resources</h3>
<ul>
<li><a href="http://developer.yahoo.com/performance/rules.html">Best Practices for Speeding Up Your Web Site</a></li>
<li><a href="http://jsperf.com/">jsPerf — JavaScript performance playground</a></li>
<li><a href="http://www.webpagetest.org/">WebPageTest &#8211; Test a website&#8217;s performance</a></li>
<li><a href="http://yostudios.github.com/Spritemapper/">Spritemapper &#8211; CSS Spritemap Generator</a></li>
<li><a href="http://pagespeed.googlelabs.com/pagespeed/">Page Speed Online</a></li>
<li><a href="http://nuget.org/List/Packages/AspNetSprites-Core">ASP.NET CSS Sprites</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/" rel="bookmark" title="June 20, 2010">CSS and JavaScript compression and bundling</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/05/transparent-pngs/" rel="bookmark" title="May 5, 2009">Transparent PNGs</a></li>
<li><a href="http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/" rel="bookmark" title="October 7, 2011">Installing EPiServer Live Monitor on IIS 7 running .NET 4</a></li>
</ul>
<p><!-- Similar Posts took 19.206 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Part 1: Injection &#8211; OWASP Top 10 for EPiServer Developers</title>
		<link>http://www.frederikvig.com/2011/05/part-1-injection-owasp-top-10-for-episerver-developers-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=part-1-injection-owasp-top-10-for-episerver-developers-3</link>
		<comments>http://www.frederikvig.com/2011/05/part-1-injection-owasp-top-10-for-episerver-developers-3/#comments</comments>
		<pubDate>Sun, 22 May 2011 13:04:02 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[OWASP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1577</guid>
		<description><![CDATA[Injection flaws have always been one of the biggest security wholes in web applications. The good news is that it is very easy to protect against them, ones you know how. So what is injection? Injection flaws, such as SQL, OS, and LDAP injection, occur when untrusteddata is sent to an interpreter as part of ...]]></description>
			<content:encoded><![CDATA[<p>Injection flaws have always been one of the biggest security wholes in web applications. The good news is that it is very easy to protect against them, ones you know how.</p>
<p>So what is injection?</p>
<blockquote>
<p>
Injection flaws, such as SQL, OS, and LDAP injection, occur when untrusteddata is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing unauthorized data.
</p>
</blockquote>
<p>What this means is that evil input data (from querystrings, form data, HTTP Headers etc) cause your applications queries or commands to change (in a way not designed by you as the developer of the application).</p>
<p>The most common form is SQL injection. Eg:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> query <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SELECT * FROM customers WHERE ID='&quot;</span> <span style="color: #008000;">+</span> Request<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;id&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>The attacker can then simple modify either the querystring, form data or the HTTP header collection. </p>
<p>http://example.com/customers?id=&#8217; or &#8217;1&#8242;=&#8217;1</p>
<p>This allows the attacker to view the customer information they like, or even go as far as deleting the table (if they run in a user context that has enough database rights).</p>
<p>One way to fix this is to either use parameters or stored procedures:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> query <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SELECT * FROM customers WHERE ID=@id&quot;</span><span style="color: #008000;">;</span>
SqlCommand command <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlCommand<span style="color: #008000;">&#40;</span>query, connection<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
SqlParameter idParameter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlParameter<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;@id&quot;</span>, SqlDbType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Int</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> Value <span style="color: #008000;">=</span> Request<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;id&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
command<span style="color: #008000;">.</span><span style="color: #0000FF;">Parameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>idParameter<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>This is better, now when someones tries to run http://example.com/app/accountView?id=&#8217; or &#8217;1&#8242;=&#8217;1 they&#8217;ll get an error (since we&#8217;ve defined that id is an integer, ADO.NET takes care of sanitizing the input).</p>
<h3>Validate all input</h3>
<p>First rule is to always code defensively. An attacker can easily modify everything sent to you, without needing a HTML form. HTTP proxies like <a href="http://www.fiddler2.com/fiddler2/">Fiddler</a> make this easy. It is much safer for us to whitelist input (specify what we consider valid input), than to blacklist input (specify what is not allowed). The reason for this is simple, you know what is accepted and valid and can make sure that the input matches that pattern. With blacklisting there is a infinitive number of different patterns we&#8217;d need to validate against.</p>
<p>In the case above where we accept an ID, which in our case only consists of integers. We can use the int.TryParse() method to validate the input:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">int</span> id<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span>Request<span style="color: #008000;">.</span><span style="color: #0000FF;">QueryString</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;id&quot;</span><span style="color: #008000;">&#93;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> id<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  lblMessage<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Invalid customer id.&quot;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// valid integer number</span></pre>
</div>
</div>
<p>Notice that we now only check the querystring (I&#8217;m not using Request["id"] anymore), We also validate and make sure that this is a number. Taking this a step further we could make sure that the number follows a pattern that we&#8217;ve defined for customer IDs (at least 4 digits, only positive numbers etc), by using a regular expression.</p>
<h3>Dynamic Data Store</h3>
<p>With EPiServer CMS 6 came the Dynamic Data Store, (more information on <a href="http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-6-R2/Dynamic-Data-Store/">Dynamic Data Store</a>). EPiServer has a factory class for accessing the dynamic data store: DynamicDataStoreFactory. We then use LINQ and Lambda to query the data. If you&#8217;ve used ORM tools like NHibernate, LINQ to SQL, Entity Framework etc before this should be familiar. The LINQ and Lambda code then gets translated to SQL code by both using parameters and stored procedures (which protect us against SQL-injections). If you&#8217;re curious how this code looks, take a look at the <a href="http://sdk.episerver.com/episerverframework/6.2/html/AllMembers_T_EPiServer_Data_Dynamic_Providers_SqlServerDataStoreProvider.htm">SqlServerDataStoreProvider class</a> in EPiServer.Data.dll.</p>
<p>Always, always use EPiServer&#8217;s API when accessing EPiServer data. Not only does it protect against security vulnerbilities like SQL-injection, it also adds smart caching, event notifications and other goodies.<br />
<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/" rel="bookmark" title="September 17, 2009">Extending search field with suggestion box</a></li>
<li><a href="http://www.frederikvig.com/2009/06/using-multiple-forms-on-an-asp-net-web-forms-page/" rel="bookmark" title="June 21, 2009">Using multiple forms on an ASP.NET web forms page</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-5-creating-the-search-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 16, 2009">Part 5: Creating the search page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/10/how-to-add-support-for-iframes-and-other-elements-to-tinymce-in-episerver-cms/" rel="bookmark" title="October 18, 2010">How to add support for iframes (and other elements) to TinyMCE in EPiServer CMS</a></li>
<li><a href="http://www.frederikvig.com/2010/04/detecting-ajax-requests-on-the-server/" rel="bookmark" title="April 6, 2010">Detecting Ajax requests on the server</a></li>
</ul>
<p><!-- Similar Posts took 18.725 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/05/part-1-injection-owasp-top-10-for-episerver-developers-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction &#8211; OWASP Top 10 for EPiServer Developers</title>
		<link>http://www.frederikvig.com/2011/05/introduction-owasp-top-10-for-episerver-developers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introduction-owasp-top-10-for-episerver-developers</link>
		<comments>http://www.frederikvig.com/2011/05/introduction-owasp-top-10-for-episerver-developers/#comments</comments>
		<pubDate>Fri, 06 May 2011 08:27:44 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[OWASP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1533</guid>
		<description><![CDATA[The Open Web Application Security Project (OWASP), is an open community that focuses on improving web application security. OWASP Top 10 is a list of the most critical web application security risks. Here is the 2010 list: Injection Cross-Site Scripting (XSS) Broken Authentication and Session Management Insecure Direct Object References Cross-Site Request Forgery (CSRF) Security ...]]></description>
			<content:encoded><![CDATA[<p>The Open Web Application Security Project (<a href="http://www.owasp.org">OWASP</a>), is an open community that focuses on improving web application security. <a href="https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project">OWASP Top 10</a> is a list of the most critical web application security risks. Here is the 2010 list:</p>
<ol>
<li><a href="http://www.frederikvig.com/2011/05/part-1-injection-owasp-top-10-for-episerver-developers-3/">Injection</a></li>
<li>Cross-Site Scripting (XSS)</li>
<li>Broken Authentication and Session Management</li>
<li>Insecure Direct Object References</li>
<li>Cross-Site Request Forgery (CSRF)</li>
<li>Security Misconfiguration</li>
<li>Insecure Cryptographic Storage</li>
<li>Failure to Restrict URL Access</li>
<li>Insufficient Transport Layer Protection</li>
<li>Unvalidated Redirects and Forwards</li>
</ol>
<p>In this series I&#8217;m going to explain the 10 security risks and how we as EPiServer developers (or ASP.NET) can protect us against exposing them in our web applications, we&#8217;ll also look at tools for analyzing web applications to find security flaws and how we as developers should think about security when developing.</p>
<p>Hope you&#8217;ll enjoy this series. Feedback is as always welcome.</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/05/part-1-injection-owasp-top-10-for-episerver-developers-3/" rel="bookmark" title="May 22, 2011">Part 1: Injection &#8211; OWASP Top 10 for EPiServer Developers</a></li>
<li><a href="http://www.frederikvig.com/2011/02/links-for-episerver-developers-1/" rel="bookmark" title="February 9, 2011">Links for EPiServer Developers &#8211; #1</a></li>
<li><a href="http://www.frederikvig.com/2011/03/links-for-episerver-developers-2/" rel="bookmark" title="March 12, 2011">Links for EPiServer Developers &#8211; #2</a></li>
<li><a href="http://www.frederikvig.com/2009/12/introduction-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 1, 2009">Introduction &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
</ul>
<p><!-- Similar Posts took 13.098 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/05/introduction-owasp-top-10-for-episerver-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Links for EPiServer Developers &#8211; #2</title>
		<link>http://www.frederikvig.com/2011/03/links-for-episerver-developers-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=links-for-episerver-developers-2</link>
		<comments>http://www.frederikvig.com/2011/03/links-for-episerver-developers-2/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 12:47:30 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1504</guid>
		<description><![CDATA[If you have any link suggestions please email me at: frederikvig@hotmail.com. Security web.config Security Analyzer &#8211; onlien and offline tool for checking your sites web.config for security vulnerabilities ASP.NET Create PDF document using iTextSharp in ASP.Net 4.0 and MemoryMappedFile RazorEngine &#8211; use the powerful Razor template engine in your project. I&#8217;ve used this for newsletter ...]]></description>
			<content:encoded><![CDATA[<p>If you have any link suggestions please email me at: <a href="mailto:frederikvig@hotmail.com">frederikvig@hotmail.com</a>.</p>
<h3>Security</h3>
<ul>
<li><a href="http://www.wcanalyzer.com/">web.config Security Analyzer</a> &#8211; onlien and offline tool for checking your sites web.config for security vulnerabilities</li>
</ul>
<h3>ASP.NET</h3>
<ul>
<li><a href="http://weblogs.asp.net/sreejukg/archive/2011/03/07/create-pdf-document-using-itextsharp-in-asp-net-4-0-and-memorymappedfile.aspx">Create PDF document using iTextSharp in ASP.Net 4.0 and MemoryMappedFile</a></li>
<li><a href="http://razorengine.codeplex.com/">RazorEngine</a> &#8211; use the powerful Razor template engine in your project. I&#8217;ve used this for newsletter templates with great success.</li>
</ul>
<h3>Performance</h3>
<ul>
<li><a href="http://aspnet.codeplex.com/releases/view/61896">ASP.NET Sprite and Image Optimization</a> &#8211; Easily generate CSS sprites. Works for both ASP.NET Webforms and MVC</li>
<li><a href="http://isis.codeplex.com/">Isis</a> &#8211; great new tool for cache management</li>
</ul>
<h3>Tools</h3>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/">User Agent-Switcher addon for Firefox</a> &#8211; great for when developing for Mobile devices or just seeing what Google sees when it indexes your site</li>
</ul>
<h3>EPiServer</h3>
<ul>
<li><a href="https://www.coderesort.com/p/epicode/wiki/Extensions">EPiCode Extensions</a> &#8211; over 80 extension methods for EPiServer</li>
<li><a href="http://world.episerver.com/Blogs/David-Knipe/Dates/2010/5/Customising-the-EPiServer-UI/">Customising the EPiServer UI</a> &#8211; nice post by David Knipe that shows how powerful EPiServer&#8217;s customization and plugin system is</li>
<li><a href="http://world.episerver.com/Blogs/Lee-Crowe/Dates/2011/3/ElencySolutionsMultipleProperty-v11-Released/">ElencySolutions.MultipleProperty v1.1 Released</a></li>
<li><a href="http://world.episerver.com/Blogs/Jonas-Bergqvist/Dates/2011/2/Generic-Find-method-in-Dynamic-data-store/">Typed “Find” method in Dynamic data store</a></li>
<li><a href="http://joelabrahamsson.com/entry/getting-started-with-episerver-cms-development">Getting started with EPiServer CMS development</a> &#8211; great post by Joel Abrahamsson for new developers to EPiServer</li>
<li><a href="http://blog.fredrikhaglund.se/blog/2011/03/22/new-stuff-in-episerver-cms-6-r2/">New stuff in EPiServer CMS 6 R2</a> &#8211; nice overview by Fredrik Haglund</li>
<li><a href="http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2011/3/Container-pages/">Container pages</a> &#8211; new type of page in EPiServer CMS 6 R2</li>
<li><a href="http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2011/3/Changes-to-the-EPiServer-CMS-Globalization/">Changes to the EPiServer CMS Globalization</a></li>
<li><a href="http://world.episerver.com/Blogs/David-Knipe/Dates/2010/9/Checklist-for-setting-up-Windows-Authentication-in-EPiServer-on-a-development-machine/">Checklist for setting up Windows Authentication in EPiServer on a development machine</a></li>
<li><a href="http://world.episerver.com/Articles/Items/Relate-Intranet-Demo-Site/">Relate Intranet Demo Site </a> &#8211; Demo templates for a social intranet</li>
</ul>
<h3>Videos</h3>
<ul>
<li><a href="http://stevesmithblog.com/blog/asp-net-tips-and-tricks-on-dnrtv/">ASP.NET Tips and Tricks on dnrTV</a> &#8211; Steve Smith goes through a lot in this video, from tracing and caching to performance optimizing ASP.NET MVC 3 applications</li>
</ul>
<h3>HTML, CSS, JavaScript</h3>
<ul>
<li><a href="http://www.smashingmagazine.com/2011/03/11/syncing-content-with-html5-video/">Syncing Content With HTML5 Video</a> &#8211; excellent article that gives you a taste for what is possible with HTML5 Video and interactions on your web page (interacting with Google Maps or similar at certain points in the video for instance)</li>
<li><a href="http://popcornjs.org/">Popcorn.js</a> &#8211; HTML5 Video event Framework, with a lot of plugins for Google Maps, Wikipedia, Flickr etc</li>
<li><a href="http://butterapp.org/">Butter</a> &#8211; Popcorn.js authoring tool</li>
<li><a href="http://www.456bereastreet.com/archive/201103/flexible_height_vertical_centering_with_css_beyond_ie7/">Flexible height vertical centering with CSS, beyond IE7</a></li>
<li><a href="http://html5boilerplate.com/">HTML5 Boilerplate</a> &#8211; great start for new projects</li>
<li><a href="https://github.com/paulirish/html5-boilerplate-server-configs/blob/master/web.config">Web.config for HTML5 Boilerplate</a></li>
<li><a href="http://msdn.microsoft.com/en-us/ie/ff468705.aspx">Internet Explorer 9 Guide for Developers</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc351024">CSS Compatibility and Internet Explorer</a></li>
<li><a href="http://www.pluginquery.com/">Search for jQuery plugins</a> &#8211; search engine that&#8217;ll help you find jQuery plugins</li>
<li><a href="http://bonsaiden.github.com/JavaScript-Garden/">JavaScript Garden</a> &#8211; JavaScript Garden is a growing collection of documentation about the most quirky parts of the JavaScript programming language.</li>
</ul>
<h3>Mobile</h3>
<ul>
<li><a href="http://51degrees.codeplex.com/">51 Degrees Mobile Device Detection and Redirection</a> &#8211; Based on the <a href="http://wurfl.sourceforge.net/">WURFL project</a>. Setup rules for mobile devices visiting your site</li>
</ul>
<h3>Web</h3>
<ul>
<li><a href="http://programmers.stackexchange.com/questions/46716/what-should-a-developer-know-before-building-a-public-web-site">What should a developer know before building a public web site?</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/02/links-for-episerver-developers-1/" rel="bookmark" title="February 9, 2011">Links for EPiServer Developers &#8211; #1</a></li>
<li><a href="http://www.frederikvig.com/2010/04/backup-plan-when-loading-the-jquery-library-from-cdn/" rel="bookmark" title="April 20, 2010">Backup plan when loading the jQuery library from CDN</a></li>
<li><a href="http://www.frederikvig.com/2009/10/creating-a-mobile-version-of-a-web-site/" rel="bookmark" title="October 4, 2009">Creating a mobile version of a web site</a></li>
<li><a href="http://www.frederikvig.com/2009/05/transparent-pngs/" rel="bookmark" title="May 5, 2009">Transparent PNGs</a></li>
<li><a href="http://www.frederikvig.com/2009/07/asp-net-web-forms-and-jquery-thickbox-plugin/" rel="bookmark" title="July 13, 2009">ASP.NET web forms and jQuery Thickbox plugin</a></li>
</ul>
<p><!-- Similar Posts took 18.228 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/03/links-for-episerver-developers-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for EPiServer Developers &#8211; #1</title>
		<link>http://www.frederikvig.com/2011/02/links-for-episerver-developers-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=links-for-episerver-developers-1</link>
		<comments>http://www.frederikvig.com/2011/02/links-for-episerver-developers-1/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 16:18:20 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1489</guid>
		<description><![CDATA[First post in a new series where I&#8217;ll post a list of links to useful resources for EPiServer developers. If you have any link suggestions please email me at: frederikvig@hotmail.com. Security Web Application Configuration Security Revisited &#8211; useful security checklist to go through before launching new sites (or existing) JavaScript Captcha &#8211; good post that ...]]></description>
			<content:encoded><![CDATA[<p>First post in a new series where I&#8217;ll post a list of links to useful resources for EPiServer developers. If you have any link suggestions please email me at: <a href="mailto:frederikvig@hotmail.com">frederikvig@hotmail.com</a>.</p>
<h3>Security</h3>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/magazine/gg309184.aspx">Web Application Configuration Security Revisited</a> &#8211; useful security checklist to go through before launching new sites (or existing)</li>
<li><a href="http://gatekiller.co.uk/Post/JavaScript_Captcha">JavaScript Captcha</a> &#8211; good post that discusses the problems with todays approach to securing against spam bots, and that suggest another approach using JavaScript and timing instead.</li>
</ul>
<h3>Deployment</h3>
<ul>
<li><a href="http://www.troyhunt.com/2010/11/you-deploying-it-wrong-teamcity.html">You&#8217;re deploying it wrong! TeamCity, Subversion &amp; Web Deploy part 1: Config transforms</a></li>
<li><a href="http://www.troyhunt.com/2011/02/automated-database-releases-with.html">Automated database releases with TeamCity and Red Gate</a></li>
</ul>
<h3>Performance</h3>
<ul>
<li><a href="http://yahoo.github.com/boomerang/doc/">Boomerang</a> &#8211; JavaScript library developed by Yahoo! for measuring the performance of a website from a client (end user&#8217;s) point of view. Along with <a href="http://developer.yahoo.com/yslow/">YSlow</a> (also from Yahoo!) and <a href="http://code.google.com/speed/page-speed/">Page Speed</a> this is a very useful tool to have.</li>
<li><a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/03/c.net-little-wonders-the-useful-but-overlooked-sets.aspx">C#/.NET Little Wonders: The Useful But Overlooked Sets</a> &#8211; good post that explains Sets collections (and their changes in .NET 4) and when to use them.</li>
<li><a href="http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2011/1/Performance-improvements-in-CMS6R2/">Performance improvements in EPiServer CMS6R2</a></li>
</ul>
<h3>Tools</h3>
<ul>
<li><a href="http://nuget.org/">NuGet</a> &#8211; very useful tool developed by Microsoft and the community for easily adding open source modules to your project. Mark Everard wrote a <a href="http://www.markeverard.com/blog/2010/11/04/using-nuget-for-episerver-third-party-libraries/">nice post</a> where he goes through adding <a href="http://pagetypebuilder.codeplex.com">Page Type Builder</a> as a NuGet package (anyone up for creating an EPiServer NuGet feed? <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</li>
<li><a href="http://weblogs.asp.net/scottgu/archive/2011/01/20/microsoft-web-farm-framework-2-0.aspx">Microsoft Web Farm Framework 2.0</a></li>
<li><a href="http://www.iis.net/download/webdeploy">Web Deploy 2.0</a></li>
</ul>
<h3>EPiServer</h3>
<ul>
<li><a href="http://world.episerver.com/Blogs/Anders-Hattestad/Dates/2011/1/Dynamic-Data-Store-and-new-properties-on-Types/">Dynamic Data Store and new properties on Types</a> &#8211; very useful extension method by Anders Hattestad for the dynamic data store. Remapping is something that most get wrong the first time they work with DDS.</li>
<li><a href="http://antecknat.se/blog/2009/11/02/creating-classes-for-pagetypebuilder-in-an-existing-project/">Creating classes for PageTypeBuilder in an existing project</a> &#8211; just because it is so awesome and alot of people don&#8217;t know about it <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</li>
<li><a href="http://world.episerver.com/Blogs/Lee-Crowe/Dates/2011/2/FilteredPageReference-v11-Released/">FilteredPageReference v1.1 Released</a></li>
<li><a href="http://world.episerver.com/Blogs/Alexander-Haneng/Dates/2011/1/Starting-a-CMS-6-sites-faster-after-build/">Starting CMS 6 sites faster after build</a> &#8211; very useful tips &#8211; especially when working with EPiServer Community</li>
<li><a href="http://www.markeverard.com/blog/2010/09/29/developing-a-custom-workflow-in-episerver-part-one/">Developing a custom workflow in EPiServer</a> &#8211; nice 4 part series on how to develop workflows for EPiServer</li>
</ul>
<h3>Code</h3>
<ul>
<li><a href="http://dotnetslackers.com/articles/aspnet/5-Helpful-DateTime-Extension-Methods.aspx">5 Helpful DateTime Extension Methods</a></li>
</ul>
<h3>Database</h3>
<ul>
<li><a href="http://www.troyhunt.com/2011/02/unnecessary-evil-of-shared-development.html">The unnecessary evil of the shared development database</a></li>
</ul>
<h3>HTML, CSS, JavaScript</h3>
<ul>
<li><a href="http://stephenwalther.com/blog/archive/2011/01/12/asp-net-and-html5-local-storage.aspx">ASP.NET and HTML5 Local Storage</a> &#8211; HTML local storage is one of the coolest new features of HTML 5. Here you&#8217;ll get a nice introduction and how to use it in your ASP.NET application.</li>
<li><a href="http://addyosmani.com/blog/large-scale-jquery/">Building Large-Scale jQuery Applications</a> &#8211; When you start using jQuery and JavaScript in larger scale your code can become very messy after a while. This post has some nice pointers on structuring your code, testing and other goodies.</li>
</ul>
<h3>ReSharper</h3>
<ul>
<li><a href="http://codebetter.com/jameskovacs/2011/01/31/easier-debugging-with-resharper-and-the-clipboard/">Easier Debugging with ReSharper and the Clipboard</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/03/links-for-episerver-developers-2/" rel="bookmark" title="March 12, 2011">Links for EPiServer Developers &#8211; #2</a></li>
<li><a href="http://www.frederikvig.com/2011/05/introduction-owasp-top-10-for-episerver-developers/" rel="bookmark" title="May 6, 2011">Introduction &#8211; OWASP Top 10 for EPiServer Developers</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2011/06/episerver-mail-5-r2-the-stored-procedure-spepiservermailsamplerecipientsourcegetmailinglists-doesnt-exist/" rel="bookmark" title="June 2, 2011">EPiServer Mail 5 R2: The stored procedure &#8216;spEPiServerMailSampleRecipientSourceGetMailingLists&#8217; doesn&#8217;t exist</a></li>
<li><a href="http://www.frederikvig.com/2010/04/backup-plan-when-loading-the-jquery-library-from-cdn/" rel="bookmark" title="April 20, 2010">Backup plan when loading the jQuery library from CDN</a></li>
</ul>
<p><!-- Similar Posts took 15.026 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/02/links-for-episerver-developers-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating custom templates in Visual Studio</title>
		<link>http://www.frederikvig.com/2011/01/creating-custom-templates-in-visual-studio/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-custom-templates-in-visual-studio</link>
		<comments>http://www.frederikvig.com/2011/01/creating-custom-templates-in-visual-studio/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 16:40:37 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1468</guid>
		<description><![CDATA[One abit hidden featured in Visual Studio is the custom item templates and projects feature. This allows you to easily export a project or item as a template, which you then can easily reuse across different projects, and even share between your collegues and team mates. This makes it very easy to create templates for ...]]></description>
			<content:encoded><![CDATA[<p>One abit hidden featured in Visual Studio is the custom item templates and projects feature. This allows you to easily export a project or item as a template, which you then can easily reuse across different projects, and even share between your collegues and team mates. This makes it very easy to create templates for your projects that follow the best practices you and your team mates have agreed on.</p>
<p>At <a href="http://geta.no">Geta</a> we have a set of guidelines and best practices that we follow in our projects. For instance we turn off ViewState and EventWireUp. The reason for turning off EventWireup is because of performance. When it&#8217;s turned on (default), ASP.NET uses reflection to look for special methods like Page_Load. What we do instead is override the OnLoad method. We also inherit from base classes and use master pages. Our user controls and web forms usually look something like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ PageLanguage<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> MasterPageFile<span style="color: #008000;">=</span><span style="color: #666666;">&quot;~/Templates/MasterPages/Site.Master&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> EnableViewState<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;WebForm1.aspx.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Web.WebForm1&quot;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Content runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ContentPlaceHolderID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ContentRegion&quot;</span><span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Content<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">PageTypes</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Web.Templates.Base</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Web
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> WebForm1 <span style="color: #008000;">:</span> TemplatePageBase<span style="color: #008000;">&lt;</span>BasePageData<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Control Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> EnableViewState<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;WebUserControl1.ascx.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Web.WebUserControl1&quot;</span> <span style="color: #008000;">%&gt;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">PageTypes</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Web.Templates.Base</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Web
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> WebUserControl1 <span style="color: #008000;">:</span> UserControlBase<span style="color: #008000;">&lt;</span>BasePageData<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>To convert this item to a item template go to File -> Export Template. Choose Item template and select the web form and user control, click next and give it a name and description. </p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/export-template-wizard.png" alt="Export Template Wizard in Visual Studio" />
</p>
<p>When we now create a new item we can choose from our newly created item templates.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/item-templates.png" alt="New item dialog in Visual Studio" />
</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/10/creating-an-episerver-plugin/" rel="bookmark" title="October 8, 2009">Creating an EPiServer Plugin</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-7-creating-the-sitemap-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 22, 2009">Part 7: Creating the Sitemap page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/05/episerver-custom-property-with-custom-settings/" rel="bookmark" title="May 14, 2010">EPiServer Custom Property with Custom Settings</a></li>
<li><a href="http://www.frederikvig.com/2010/01/a-developers-guide-to-pagetypebuilder/" rel="bookmark" title="January 15, 2010">A developer&#8217;s guide to Page Type Builder</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-2-creating-a-foundation-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 7, 2009">Part 2: Creating a foundation &#8211; Create an EPiServer site from scratch</a></li>
</ul>
<p><!-- Similar Posts took 21.884 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/01/creating-custom-templates-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing HTTP Headers for ASP.NET sites</title>
		<link>http://www.frederikvig.com/2010/11/removing-http-headers-for-asp-net-sites/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=removing-http-headers-for-asp-net-sites</link>
		<comments>http://www.frederikvig.com/2010/11/removing-http-headers-for-asp-net-sites/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 10:02:38 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Umbraco]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1447</guid>
		<description><![CDATA[By default IIS and ASP.NET add a couple informational HTTP Headers to a response. They add extra traffic and give away security information like ASP.NET version, IIS version etc. To see the HTTP Header you can use a proxy tool like Fiddler or Live HTTP Header. The example below is for a regular ASP.NET site. ...]]></description>
			<content:encoded><![CDATA[<p>By default IIS and ASP.NET add a couple informational HTTP Headers to a response. They add extra traffic and give away security information like ASP.NET version, IIS version etc. To see the HTTP Header you can use a proxy tool like Fiddler or Live HTTP Header. The example below is for a regular ASP.NET site.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/http-headers/http-headers.png" alt="HTTP Header for a typical ASP.NET site" />
</p>
<h3>Removing the X-Powered-By Header</h3>
<p>Open up IIS Manager, choose your site and go to HTTP Response Headers. Here you&#8217;ll see X-Powered-By being inherited. You can either remove it only for this site or for all sites on this server (select the server name in IIS Manager and HTTP Response Headers).</p>
<p>You can also do this in your sites web.config.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span><span style="color: #000000;">system</span><span style="color: #008000;">.</span><span style="color: #0000FF;">webServer</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">...</span>
<span style="color: #008000;">&lt;</span>httpProtocol<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>customHeaders<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>remove name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;X-Powered-By&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>customHeaders<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>httpProtocol<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">...</span>
<span style="color: #008000;">&lt;/</span><span style="color: #000000;">system</span><span style="color: #008000;">.</span><span style="color: #0000FF;">webServer</span><span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<h3>Removing the Server Header</h3>
<p>To remove this HTTP Header we need to create a custom HTTP Module.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> MyNamespace
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> HttpHeadersCleanup <span style="color: #008000;">:</span> IHttpModule
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Init<span style="color: #008000;">&#40;</span>HttpApplication context<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            context<span style="color: #008000;">.</span><span style="color: #0000FF;">PreSendRequestHeaders</span> <span style="color: #008000;">+=</span> PreSendRequestHeaders<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> PreSendRequestHeaders<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Headers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Server&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Dispose<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>You also need to register the HTTP Module in your sites web.config.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules</span> <span style="color: #000066;">runAllManagedModulesForAllRequests</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HttpHeadersCleanup &quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;MyNamespace.HttpHeadersCleanup, MyAssembly&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<h3>Removing the ETag Header</h3>
<p>For more information on ETag see: <a href="http://en.wikipedia.org/wiki/HTTP_ETag">HTTP ETag</a>.</p>
<p>To remove ETag you need to add the code below to the HTTP Module described previously.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Headers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ETag&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h3>Removing the X-Aspnet-Version Header</h3>
<p>To remove this HTTP Header you simply set enableVersionHeader to false in your sites web.config.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span><span style="color: #000000;">system.<span style="color: #0000FF;">web</span></span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">...</span>
    <span style="color: #008000;">&lt;</span>httpRuntime enableVersionHeader<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> <span style="color: #008000;">/&gt;</span>
<span style="color: #008000;">...</span>
<span style="color: #008000;">&lt;/</span><span style="color: #000000;">system.<span style="color: #0000FF;">web</span></span><span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>Or by removing it in the HTTP Module:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Headers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;X-AspNet-Version&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>Here&#8217;s how the HTTP Headers look now:</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/http-headers/new-http-headers.png" alt="New HTTP Headers after removing X-Powered-By Header, Server, and ETag" />
</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/04/detecting-ajax-requests-on-the-server/" rel="bookmark" title="April 6, 2010">Detecting Ajax requests on the server</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/" rel="bookmark" title="October 9, 2011">Faster EPiServer sites &#8211; client side performance</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-1-setting-up-the-development-environment-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 4, 2009">Part 1: Setting up the development environment &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/02/getting-the-page-and-episerver-currentpage-object-from-httpcontext/" rel="bookmark" title="February 20, 2010">Getting the Page and EPiServer CurrentPage object from HttpContext</a></li>
</ul>
<p><!-- Similar Posts took 18.716 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/11/removing-http-headers-for-asp-net-sites/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Session with ASP.NET Web Services and Generic Handlers</title>
		<link>http://www.frederikvig.com/2010/11/using-session-with-asp-net-web-services-and-generic-handlers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-session-with-asp-net-web-services-and-generic-handlers</link>
		<comments>http://www.frederikvig.com/2010/11/using-session-with-asp-net-web-services-and-generic-handlers/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 14:37:03 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1420</guid>
		<description><![CDATA[After refactoring some code today, going from cookies to using ASP.NET session instead, I noticed some problems with the Web Services and Generic Handlers (this application used a lot of JavaScript and Ajax). The problem was that the Session collection was always null. After checking out the documentation on MSDN I came across the solution ...]]></description>
			<content:encoded><![CDATA[<p>After refactoring some code today, going from cookies to using ASP.NET session instead, I noticed some problems with the Web Services and Generic Handlers (this application used a lot of JavaScript and Ajax). The problem was that the Session collection was always null. After checking out the documentation on <a href="http://msdn.com">MSDN</a> I came across the solution (turned out be quite simple).</p>
<h3>Web Services</h3>
<p>In the WebMethod attribute you need to set the property EnableSession to true (told you it was simple).</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.ServiceModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Script.Services</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Services</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Coop<span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Templates</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WebServices</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MegaStore</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#91;</span>WebService<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">Namespace</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://schema.company.com&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>XmlSerializerFormat<span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>WebServiceBinding<span style="color: #008000;">&#40;</span>ConformsTo <span style="color: #008000;">=</span> WsiProfiles<span style="color: #008000;">.</span><span style="color: #0000FF;">BasicProfile1_1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToolboxItem</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>ScriptService<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Manager <span style="color: #008000;">:</span> WebService
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">&#91;</span>WebMethod<span style="color: #008000;">&#40;</span>EnableSession <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> MyMethod<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// you can now use the session collection: Session</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h3>Generic Handlers</h3>
<p>For Generic Handlers you need to implement the interface IReadOnlySessionState, located in System.Web.SessionState.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.SessionState</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Playground
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyGenericHandler<span style="color: #008000;">:</span> IHttpHandler, IReadOnlySessionState
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ProcessRequest<span style="color: #008000;">&#40;</span>HttpContext context<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// you can now use the session collection: context.Session</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsReusable
        <span style="color: #008000;">&#123;</span>
            get
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/11/removing-http-headers-for-asp-net-sites/" rel="bookmark" title="November 26, 2010">Removing HTTP Headers for ASP.NET sites</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/" rel="bookmark" title="November 27, 2009">Removing duplicates from a PageDataCollection</a></li>
<li><a href="http://www.frederikvig.com/2011/09/tags-version-0-2-released-for-episerver-cms/" rel="bookmark" title="September 5, 2011">Tags version 0.2 released for EPiServer CMS</a></li>
<li><a href="http://www.frederikvig.com/2009/05/aspnet-validation-and-jquery/" rel="bookmark" title="May 21, 2009">ASP.NET Validation and jQuery</a></li>
</ul>
<p><!-- Similar Posts took 26.848 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/11/using-session-with-asp-net-web-services-and-generic-handlers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Guide to EPiCode Extensions</title>
		<link>http://www.frederikvig.com/2010/09/guide-to-epicode-extensions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=guide-to-epicode-extensions</link>
		<comments>http://www.frederikvig.com/2010/09/guide-to-epicode-extensions/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 20:34:09 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[EPiCode]]></category>
		<category><![CDATA[EPiCode.Extensions]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1354</guid>
		<description><![CDATA[Last updated: 21.11.2010 EPiCode Extensions is a library with over 75 extension methods that are really useful to us as EPiServer developers. The project has grown rapidly in short time, with new extension methods being added every week. The goal of the library is to help out with the most used tasks during development of ...]]></description>
			<content:encoded><![CDATA[<p>Last updated: 21.11.2010</p>
<p><a href="https://www.coderesort.com/p/epicode/wiki/Extensions">EPiCode Extensions</a> is a library with over 75 extension methods that are really useful to us as EPiServer developers. The project has grown rapidly in short time, with new extension methods being added every week.</p>
<p>The goal of the library is to help out with the most used tasks during development of an EPiServer site and make them easy and fun to use and extend.</p>
<p>Note: this blog post is a work in progress and will be updated as the library progresses.</p>
<h3>Encoding</h3>
<h4>ToWebString</h4>
<p>This extension method will remove all HTML code except for what is specified as allowed under your sites UISafeHtmlTags (located in episerver.config under sitesettings).</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToWebString<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">object</span> obj<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p><strong>Example 1: </strong> This example uses Page Type Builder to first check if the property Heading as any value, if so return that, if not, return PageName and then ToWebString encode it to escape HTML code that isen&#8217;t specified in UISafeHtmlTags (typically everything except for: b,i,u,br)</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>PageTypeProperty<span style="color: #008000;">&#40;</span>Searchable <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span>, SortOrder <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>, Tab <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Tabs<span style="color: #008000;">.</span><span style="color: #0000FF;">Information</span><span style="color: #008000;">&#41;</span>, Type <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>PropertyString<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">string</span> Heading
<span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPropertyValue</span><span style="color: #008000;">&#40;</span>page <span style="color: #008000;">=&gt;</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Heading</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">??</span> PageName<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToWebString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>
<strong>Example 2: </strong>This time we use ToWebString() inside a Repeater, encoding the property Name&#8217;s value.
</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Repeater runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;&lt;</span>h2<span style="color: #008000;">&gt;&lt;%</span><span style="color: #008080;"># Eval(&quot;Name&quot;).ToWebString() %&gt;&lt;/h2&gt;&lt;/ItemTemplate&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Repeater<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<h4>ToHtmlEncoded</h4>
<p>This method calls HttpUtility.HtmlEncode().</p>
<blockquote>
<p>HTML encoding makes sure that text is displayed correctly in the browser and not interpreted by the browser as HTML. For example, if a text string contains a less than sign (<) or greater than sign (>), the browser would interpret these characters as the opening or closing bracket of an HTML tag. When the characters are HTML encoded, they are converted to the strings &lt; and &gt;, which causes the browser to display the less than sign and greater than sign correctly.</p>
</blockquote>
<p><a href="http://msdn.microsoft.com/en-us/library/73z22y6h.aspx">HttpUtility.HtmlEncode method</a></p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToHtmlEncoded<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> text<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>Here I store the zip code that the user typed in, but HtmlEncode before to escape potential harmful code.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span>_stateManager<span style="color: #008000;">.</span><span style="color: #0000FF;">StoreValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;zipcode&quot;</span>, txtZipCode<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToHtmlEncoded</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>ToJavaScriptEncoded</h4>
<p>This method uses EPiServer&#8217;s ClientScriptUtility.ToScriptSafeString().</p>
<blockquote>
<p>
Make a string safe to be embedded into a script block, by replacing any characters that would invalidate the script with script-safe characters.
</p>
</blockquote>
<p>
<a href="http://sdk.episerver.com/library/cms6/html/M_EPiServer_ClientScript_ClientScriptUtility_ToScriptSafeString.htm">EPiServer&#8217;s ClientScriptUtility.ToScriptSafeString method</a>
</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToUrlEncoded<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> text<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<h4>ToUrlEncoded</h4>
<p>This method calls HttpUtility.UrlPathEncode().</p>
<blockquote cite="http://msdn.microsoft.com/en-us/library/system.web.httputility.urlpathencode.aspx">
<p>
The UrlPathEncode() method converts each space character into the string &#8220;%20&#8243;, which represents a space in hexadecimal notation. Use the UrlPathEncode()  method when you encode the path portion of a URL in order to guarantee a consistent decoded URL, regardless of which platform or browser performs the decoding.
</p>
</blockquote>
<p>
<a href="http://msdn.microsoft.com/en-us/library/system.web.httputility.urlpathencode.aspx">HttpUtility.UrlPathEncode method</a>
</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToJavaScriptEncoded<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> text<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>Here I UrlPathEncode the CurrentPages external URL.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">http<span style="color: #008000;">:</span><span style="color: #008080; font-style: italic;">//www.facebook.com/widgets/like.php?href=&lt;%= CurrentPage.GetExternalUrl().ToUrlEncoded() %&gt;</span></pre>
</div>
</div>
<h3>HTML markup</h3>
<p>Extension methods that help us produce good, clean semantic HTML markup.</p>
<h4>HtmlImage</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> imagePropertyName<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> imagePropertyName, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> imagePropertyName, <span style="color: #6666cc; font-weight: bold;">string</span> altTextPropertyName<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> imagePropertyName, <span style="color: #6666cc; font-weight: bold;">string</span> altTextPropertyName, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> imagePath<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> imagePath, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> imagePath, <span style="color: #6666cc; font-weight: bold;">string</span> altText<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> imagePath, <span style="color: #6666cc; font-weight: bold;">string</span> altText, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> imagePath, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> altText<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> imagePath, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> altText, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> imagePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> imagePath, <span style="color: #6666cc; font-weight: bold;">string</span> altText<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> imagePath, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlImage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> imagePath, <span style="color: #6666cc; font-weight: bold;">string</span> altText, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p><strong>Example 1: </strong>Here we use Page Type Builder with the property type PropertyImageUrl.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">FeaturedImage</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HtmlImage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>img alt<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;/Global/LogoTypes/logo.png&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">FeaturedImage</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HtmlImage</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;My featured image&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>img alt<span style="color: #008000;">=</span><span style="color: #666666;">&quot;My featured image&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;/Global/LogoTypes/logo.png&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">FeaturedImage</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HtmlImage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span><span style="color: #008000;">&#123;</span>@<span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;featured&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>img alt<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span> <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;featured&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;/Global/LogoTypes/logo.png&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p><strong>Example 2: </strong>Same as the previous example, only without using Page Type Builder.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">HtmlImage</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FeaturedImage&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>img alt<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;/Global/LogoTypes/logo.png&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">HtmlImage</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyValue</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FeaturedImage&quot;</span><span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;My featured image&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>img alt<span style="color: #008000;">=</span><span style="color: #666666;">&quot;My featured image&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;/Global/LogoTypes/logo.png&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">HtmlImage</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FeaturedImage&quot;</span>, <span style="color: #008000;">new</span><span style="color: #008000;">&#123;</span>@<span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;featured&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>img alt<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span> <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;featured&quot;</span> src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;/Global/LogoTypes/logo.png&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>If the property has no value no img tag will render.</p>
<h4>HtmlLink</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> linkText<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> linkText<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> linkText, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> HtmlLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> linkText, <span style="color: #6666cc; font-weight: bold;">object</span> attributes<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>For examples see: <a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/">Extending PageData with some cool Html Helpers</a>.</p>
<h4>StripHtml</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">int</span> maxTextLength<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, <span style="color: #6666cc; font-weight: bold;">int</span> maxTextLength<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> htmlText<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, Func<span style="color: #008000;">&lt;</span>PageData, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> htmlText, <span style="color: #6666cc; font-weight: bold;">int</span> maxTextLength<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> StripHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> htmlText, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">?</span> maxTextLength<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>In this example we remove all HTML markup and strip the text (if it&#8217;s to long) to a specified length.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">MainIntro</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StripHtml</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">StripHtml</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MainIntro&quot;</span>, <span style="color: #FF0000;">255</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
&nbsp;
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">255</span> characters of text<span style="color: #008000;">...&lt;/</span>p<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>This is usually used in lists.</p>
<h4>FormatHtml</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> FormatHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, <span style="color: #6666cc; font-weight: bold;">string</span> startTag, <span style="color: #6666cc; font-weight: bold;">string</span> endTag<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> FormatHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName,<span style="color: #6666cc; font-weight: bold;">string</span> format<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> FormatHtml<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> text, <span style="color: #6666cc; font-weight: bold;">string</span> startTag, <span style="color: #6666cc; font-weight: bold;">string</span> endTag<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">Author</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FormatHtml</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;p&gt;&quot;</span>, <span style="color: #666666;">&quot;&lt;/p&gt;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
Result<span style="color: #008000;">:</span> <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;</span>Frederik<span style="color: #008000;">&lt;/</span>p<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>If the property has no value nothing will get rendered.</p>
<h3>PageData and PageDataCollection</h3>
<h4>GetExternalUrl</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetExternalUrl<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetExternalUrl<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageReference pageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExternalUrl</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
Result<span style="color: #008000;">:</span> http<span style="color: #008000;">:</span><span style="color: #008080; font-style: italic;">//playground/en/Test/</span></pre>
</div>
</div>
<h4>GetDescendants</h4>
<p>This method will return either all the descending pages or all the descending pages down to a certain level. Very useful when creating lists.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>PageData<span style="color: #008000;">&gt;</span> GetDescendants<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData rootPage<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>PageData<span style="color: #008000;">&gt;</span> GetDescendants<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData rootPage, <span style="color: #6666cc; font-weight: bold;">int</span> levels<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>HasChildren</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> HasChildren<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData pageData<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>GetChildren</h4>
<p>This method returns the children of the page.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection GetChildren<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection GetChildren<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageReference pageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>GetPage</h4>
<p>This method returns a PageData object</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageData GetPage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageReference pageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>GetAncestorAtLevel</h4>
<p>Gets the ancestor at a given level from a root page. If the page provided is at this level, it is returned.</p>
<p>This method is especially useful when finding the root page for a secondary navigation structure.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageData GetAncestorAtLevel<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, PageReference rootPage, <span style="color: #6666cc; font-weight: bold;">int</span> offset<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>GetAncestors</h4>
<p>Get all the ancestors of a page or get all the ancestors of a page up to a given root page.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>PageData<span style="color: #008000;">&gt;</span> GetAncestors<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>PageData<span style="color: #008000;">&gt;</span> GetAncestors<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, PageReference rootPage<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>GetParent</h4>
<p>Gets the parent PageData object, returns null if no parent is found or if the page is in the recycle bin.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageData GetParent<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>PropertyValueWithDefault</h4>
<p>Returns the EPiServer property value. If null or empty returns default value.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> T PropertyValueWithDefault<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, T defaultValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyValueWithDefault</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MainBody&quot;</span>, <span style="color: #666666;">&quot;Nothing to see..&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre>
</div>
</div>
<h4>PropertyValue</h4>
<p>Get EPiServer property value. You&#8217;ll be using this method a lot if you don&#8217;t have Page Type Builder.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> T PropertyValue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p><strong>Example 1: </strong>Here we simply get the value of the MainIntro property.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyValue</span><span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MainIntro&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre>
</div>
</div>
<p><strong>Example 2: </strong>Here we get the value of the MyPage property (which is a Page property) and then we get the PageData object with the GetPage extension method.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyValue</span><span style="color: #008000;">&lt;</span>PageReference<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyPage&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></pre>
</div>
</div>
<h4>ToPageDataCollection</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection ToPageDataCollection <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> IEnumerable<span style="color: #008000;">&lt;</span>PageData<span style="color: #008000;">&gt;</span> pages<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection ToPageDataCollection<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> LinkItemCollection linkItemCollection<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p><strong>Example 1: </strong>Here we convert the collection to a PageDataCollection so that we can use EPiServer&#8217;s filter methods.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDescendants</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0000FF;">ToPageDataCollection</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0000FF;">FilterForVisitor</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p><strong>Example 2: </strong>Here we convert a LinkItemCollection to a PageDataCollection which makes it easier to work with the objects in the collection.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">MyLinkItemCollection</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToPageDataCollection</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                                             <span style="color: #008000;">.</span><span style="color: #0000FF;">FilterCount</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>GetProperty</h4>
<p>Sometimes we need to work with the PropertyData object of a property.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PropertyData GetProperty<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyNames<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>IsEPiServerPage</h4>
<p>Checks that this is a valid EPiServer page.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsEPiServerPage<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>IsSelected</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsSelected<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, PageData currentPage<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>See <a href="http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/">The SelectedTemplate and duplicate code</a></p>
<h4>IsPublished</h4>
<h5>Method signature</h5>
<p>Checks that the page is published.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsPublished<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>IsValue</h4>
<p>Very useful for checking if the property has any value (the one that ships with EPiServer only checks for CurrentPage, not for any PageData object).</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsValue<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>ParentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">IsValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MegaMenuLinksInColumn&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Menu</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GroupItemCount</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>ParentPage<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MegaMenuLinksInColumn&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>ToPresentationString</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToPresentationString<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PropertyXhtmlString propertyData, PageBase page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h3>Categories</h3>
<h4>GetActiveSubCategories</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> CategoryCollection GetActiveSubCategories<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> CategoryList allActiveCategoryIds, <span style="color: #6666cc; font-weight: bold;">string</span> parentCategoryName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> CategoryCollection GetActiveSubCategories<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> CategoryList allActiveCategoryIds, <span style="color: #6666cc; font-weight: bold;">int</span> parentCategoryId<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> CategoryCollection GetActiveSubCategories<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> CategoryList allActiveCategoryIds, Category parentCategory<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>See <a href="http://www.frederikvig.com/2009/11/extending-episerver-categories/">Extending EPiServer Categories</a></p>
<h3>Filters</h3>
<h4>FilterForVisitor</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterForVisitor<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterForVisitor</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>FilterAccess</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterAccess<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, AccessLevel accessLevel<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterAccess</span><span style="color: #008000;">&#40;</span>AccessLevel<span style="color: #008000;">.</span><span style="color: #0000FF;">Edit</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>FilterCompareTo</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterCompareTo<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, <span style="color: #6666cc; font-weight: bold;">string</span> propertyValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>Filters out all pages that don&#8217;t have Visible in menu set to true (checked).</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterCompareTo</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PageVisibleInMenu&quot;</span>, <span style="color: #666666;">&quot;true&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>FilterCount</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterCount<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, <span style="color: #6666cc; font-weight: bold;">int</span> count<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterCount</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>FilterPropertySort</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterPropertySort<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterPropertySort<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, FilterSortDirection filterSortDirection<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterPropertySort</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PageSortIndex&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>FilterSkipCount</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterSkipCount<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, <span style="color: #6666cc; font-weight: bold;">int</span> skipCount<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>Great for pagination.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterSkipCount</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span>
                                  <span style="color: #008000;">.</span><span style="color: #0000FF;">FilterCount</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>FilterSort</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataCollection FilterSort<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageDataCollection pageDataCollection, FilterSortOrder sortOrder<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FilterSort</span><span style="color: #008000;">&#40;</span>FilterSortOrder<span style="color: #008000;">.</span><span style="color: #0000FF;">Alphabetical</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h3>Globalization</h3>
<h4>Translate</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> Translate<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">object</span> obj, <span style="color: #6666cc; font-weight: bold;">string</span> xpath<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h3>Working with Server Controls</h3>
<h4>RenderToString</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> RenderToString<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Control control<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<h4>FindChildControls</h4>
<p>Find all child controls matching a predicate.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> FindChildControls<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Control parentControl, Predicate<span style="color: #008000;">&lt;</span>Control<span style="color: #008000;">&gt;</span> predicate<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> Control<span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p><strong>Example 1: </strong>Here we find all the TextBox controls on the page.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">FindChildControls</span><span style="color: #008000;">&lt;</span>TextBox<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> c <span style="color: #008000;">is</span> TextBox<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p><strong>Example 2: </strong>Here we find the a button on the page with the ID btnSubmit.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">FindChildControls</span><span style="color: #008000;">&lt;</span>Button<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;btnSubmit&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<h4>AddToHeader</h4>
<p>Moves a control up to the head section if it exists.</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AddToHeader<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Control control<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>AddToParent</h4>
<p>oves a control up to the first element that exists with the <a href="http://msdn.microsoft.com/en-us/library/486wc64h.aspx">FindControl method</a> .</p>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AddToParent<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Control control, <span style="color: #6666cc; font-weight: bold;">string</span> path<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h3>Working with Strings</h3>
<h4>IsNullOrEmpty</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsNullOrEmpty<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> text<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>Do something if MainIntro is null or empty.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">MainIntro</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h4>IsNotNullOrEmpty</h4>
<h5>Method signature</h5>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsNotNullOrEmpty<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> text<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h5>Example</h5>
<p>Do something if MainIntro is not null or empty.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentPage<span style="color: #008000;">.</span><span style="color: #0000FF;">MainIntro</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNotNullOrEmpty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<h3>Get started</h3>
<p>Head over to <a href="https://www.coderesort.com/p/epicode/wiki/Extensions">EPiCode</a> and <a href="https://www.coderesort.com/p/epicode/attachment/wiki/Extensions/EPiCode.Extensions.dll">download the latest release</a>. Reference EPiCode.Extensions in your project, and you&#8217;re all set! We also recommend registering the namespace in your web.config file for easy access.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;EPiCode.Extensions&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>Happy coding!<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/" rel="bookmark" title="December 8, 2009">Extending PageData with some cool Html Helpers</a></li>
<li><a href="http://www.frederikvig.com/2009/05/episerver-link-collection/" rel="bookmark" title="May 18, 2009">EPiServer Link Collection Property</a></li>
<li><a href="http://www.frederikvig.com/2009/09/creating-a-custom-episerver-paging-control/" rel="bookmark" title="September 20, 2009">Creating a Custom EPiServer Paging Control</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist/" rel="bookmark" title="July 25, 2009">EPiServer web controls: NewsList</a></li>
</ul>
<p><!-- Similar Posts took 15.497 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/09/guide-to-epicode-extensions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing oEmbed for EPiServer</title>
		<link>http://www.frederikvig.com/2010/09/introducing-oembed-for-episerver/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introducing-oembed-for-episerver</link>
		<comments>http://www.frederikvig.com/2010/09/introducing-oembed-for-episerver/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 11:05:17 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[EPiCode]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1348</guid>
		<description><![CDATA[A couple of weeks back I added a new EPiServer plugin to EPiCode, oEmbed. The plugin is really simple, but does some cool things. Imagine your editors have some content on YouTube, Amazon, Flickr etc, and they&#8217;d like to add it to their EPiServer site. oEmbed makes this really easy, all the editors need to ...]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks back I added a new EPiServer plugin to EPiCode, <a href="https://www.coderesort.com/p/epicode/wiki/oEmbed">oEmbed</a>. The plugin is really simple, but does some cool things. Imagine your editors have some content on YouTube, Amazon, Flickr etc, and they&#8217;d like to add it to their EPiServer site. oEmbed makes this really easy, all the editors need to do is paste in the URL of the content they wish to show, could be from Amazon, Viddler or any other service that support oEmbed (here&#8217;s a list of <a href="http://oohembed.com/#configuration">supported services</a>), and the plugin will automatically figure out the correct embed code for the content, doesn&#8217;t matter if it&#8217;s a Flash video or just plain HTML and CSS. </p>
<h3>Examples</h3>
<p>
<a href="http://www.frederikvig.com/wp-content/uploads/oEmbed/oEmbed-source.png"><img src="http://www.frederikvig.com/wp-content/uploads/oEmbed/oEmbed-source.png" width="600" alt="Copy URL from Amazon" /></a><br />
Simply copy the URL.
</p>
<p>
<a href="http://www.frederikvig.com/wp-content/uploads/oEmbed/oEmbed-dynamic-content.png"><img src="http://www.frederikvig.com/wp-content/uploads/oEmbed/oEmbed-dynamic-content.png" alt="Add oEmbed in EPiServer edit mode" width="600" /></a><br />
Add a new dynamic content and paste in the URL
</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/oEmbed/oEmbed-view.png" alt="oEmbed in EPiServer view mode" /><br />
And the result. Pretty cool huh?
</p>
<p>
This works for a lot of popular services and makes it so much easier than manually copying/pasting the embed code. I encourage you to take a peek at the source code, especially the oEmbedResponse.cs class to see what you get back.
</p>
<h3>Get started</h3>
<p>To get started simply <a href="https://www.coderesort.com/p/epicode/attachment/wiki/oEmbed/Geta.oEmbed.dll">download Geta.oEmbed.dll</a> and add it to your sites bin folder (note that you need to unblock it). Then you need to register the dynamic content in episerver.config:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dynamicContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controls<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      ...
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Displays an oEmbed object on the page&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;oEmbedPlugin&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Geta.oEmbed.DynamicContent.oEmbedPlugin, Geta.oEmbed&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controls<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dynamicContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>That&#8217;s it! You can now use oEmbed both as a dynamic content plugin and as a custom property.</p>
<h3>Resources</h3>
<ul>
<li><a href="http://www.oembed.com/">oEmbed</a></li>
<li><a href="http://oohembed.com/">oohEmbed</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/10/slideshare-dynamic-content/" rel="bookmark" title="October 25, 2009">SlideShare Dynamic Content</a></li>
<li><a href="http://www.frederikvig.com/2011/05/css3-buttons-and-episerver-editor-stylesheet/" rel="bookmark" title="May 8, 2011">CSS3 buttons and EPiServer editor stylesheet</a></li>
<li><a href="http://www.frederikvig.com/2009/07/asp-net-web-forms-and-jquery-thickbox-plugin/" rel="bookmark" title="July 13, 2009">ASP.NET web forms and jQuery Thickbox plugin</a></li>
<li><a href="http://www.frederikvig.com/2010/10/avoiding-conflicts-when-using-jquery-and-episerver-composer/" rel="bookmark" title="October 25, 2010">Avoiding conflicts when using jQuery and EPiServer Composer</a></li>
<li><a href="http://www.frederikvig.com/2010/04/creating-a-simple-image-gallery-with-episerver/" rel="bookmark" title="April 3, 2010">Creating a simple image gallery with EPiServer</a></li>
</ul>
<p><!-- Similar Posts took 22.760 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/09/introducing-oembed-for-episerver/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
