<?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>hamang.net</title>
	<atom:link href="http://hamang.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://hamang.net</link>
	<description>- the everyday life</description>
	<lastBuildDate>Wed, 10 Feb 2010 09:52:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating dynamic menus in EPiServer</title>
		<link>http://hamang.net/2010/02/10/creating-dynamic-menus-in-episerver/</link>
		<comments>http://hamang.net/2010/02/10/creating-dynamic-menus-in-episerver/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 09:32:42 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=201</guid>
		<description><![CDATA[My first post in almost a year! What is going on! &#034;Been busy, things are happening, blah blah blah&#034;&#8230;no excuse, really. I signed up for twitter almost a year ago, and I think I lost some focus in the blogging sphere. Anyway, this first post in 2010 is about EPiServer, the best CMS out there [...]]]></description>
			<content:encoded><![CDATA[<p><em>My first post in almost a year! What is going on! &#034;Been busy, things are happening, blah blah blah&#034;&#8230;no excuse, really.<a href="http://www.twitter.com/knut_hamang" target="_blank"> I signed up for twitter</a> almost a year ago, and I think I lost some focus in the blogging sphere. Anyway, this first post in 2010 is about EPiServer, the best CMS out there today!</em></p>
<h3>The challenge</h3>
<p>I want to create a more dynamic page tree than the standard EPiServer PageTree. More like an <a href="http://jqueryui.com/demos/accordion/#mouseover">Accordion panel </a>which has 2 or 3 levels (doesn&#039;t matter) and all available nodes are expanded by default. The real challenge is to get the whole page tree with all nodes expanded (not only the nodes which are selected) and setting correct class on the expanded items. Whether this is an accordion or another cool menu script is all the same.</p>
<h3>The Solution</h3>
<p>Start out with the default PageTree control in EPiServer controls.</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">EPiServer</span><span style="color: blue;">:</span><span style="color: #a31515;">PageTree</span> <span style="color: red;">ID</span><span style="color: blue;">=&#034;PageTreeLeftMenu&#034;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#034;server&#034;</span> <span style="color: red;">ExpandAll</span><span style="color: blue;">=&#034;true&#034;</span> <span style="color: red;">NumberOfLevels</span><span style="color: blue;">=&#034;2&#034;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">HeaderTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">div</span> <span style="color: red;">class</span><span style="color: blue;">=&#034;leftmenu&#034;&gt;</span> <span style="color: green;">&lt;!&#8211; Header &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">HeaderTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">IndentTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span> <span style="color: green;">&lt;!&#8211; Indent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">IndentTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ItemHeaderTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span> <span style="color: red;">&lt;%# GetExpandedClass(Container.DataItem) %&gt;</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ItemHeaderTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ExpandedTopTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">EPiServer</span><span style="color: blue;">:</span><span style="color: #a31515;">Property</span> <span style="color: red;">PropertyName</span><span style="color: blue;">=&#034;PageLink&#034;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#034;server&#034;</span> <span style="color: blue;">/&gt;</span> <span style="color: green;">&lt;!&#8211; ExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ExpandedTopTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">SelectedExpandedTopTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">EPiServer</span><span style="color: blue;">:</span><span style="color: #a31515;">Property</span> <span style="color: red;">PropertyName</span><span style="color: blue;">=&#034;PageLink&#034;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#034;server&#034;</span> <span style="color: red;">CssClass</span><span style="color: blue;">=&#034;selected&#034;</span> <span style="color: blue;">/&gt;</span> <span style="color: green;">&lt;!&#8211; SelectedExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">SelectedExpandedTopTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ExpandedItemTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">EPiServer</span><span style="color: blue;">:</span><span style="color: #a31515;">Property</span> <span style="color: red;">PropertyName</span><span style="color: blue;">=&#034;PageLink&#034;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#034;server&#034;</span> <span style="color: blue;">/&gt;</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ExpandedItemTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">SelectedExpandedItemTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">EPiServer</span><span style="color: blue;">:</span><span style="color: #a31515;">Property</span> <span style="color: red;">PropertyName</span><span style="color: blue;">=&#034;PageLink&#034;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#034;server&#034;</span> <span style="color: red;">CssClass</span><span style="color: blue;">=&#034;selected&#034;</span> <span style="color: blue;">/&gt;</span> <span style="color: green;">&lt;!&#8211; SelectedExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">SelectedExpandedItemTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">ItemFooterTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ItemFooterTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">UnindentTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span> <span style="color: green;">&lt;!&#8211; UnIndent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">UnindentTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">FooterTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;</span> <span style="color: green;">&lt;!&#8211; Footer &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">FooterTemplate</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EPiServer</span><span style="color: blue;">:</span><span style="color: #a31515;">PageTree</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: blue;"><br />
 </span></p>
</div>
<p>Things to notice:</p>
<ul>
<li>&#034;<strong>ExpandAll</strong>&#034; is set to true. This will dump the whole tree, not just the nodes which are selected by the user.</li>
<li>Only the <strong>*Expanded* templates</strong> are in use for Top and Item (ie.ExpandedTopTemplate).  When using &#034;ExpandAll&#034; these are the templates used, not the regular Top Template and ItemTemplate.</li>
<li>&lt;%# <strong>GetExpandedClass</strong>(Container.DataItem) %&gt; &#8211; This is the magic for setting the correct style on the expanded items. In addition there is a &#034;selected&#034; class on the selected menu item</li>
</ul>
<p>The Codebehind looks like this:</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">PageTreeLeftMenu.PageLink = LeftMenuPageLink;</p>
<p style="margin: 0px;">PageTreeLeftMenu.DataBind();</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">protected</span> <span style="color: #2b91af;">PageReference</span> LeftMenuPageLink</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">get</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: #2b91af;">PageReference</span> leftMenuPageLink = CurrentPage[<span style="color: #a31515;">"LeftMenuRoot"</span>] <span style="color: blue;">as</span> <span style="color: #2b91af;">PageReference</span>;</p>
<p style="margin: 0px;"><span style="color: blue;">return</span> leftMenuPageLink;</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">protected</span> <span style="color: blue;">string</span> GetExpandedClass(<span style="color: blue;">object</span> dataItem)</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: #2b91af;">PageData</span> page = dataItem <span style="color: blue;">as</span> <span style="color: #2b91af;">PageData</span>;</p>
<p style="margin: 0px;"><span style="color: blue;">if</span> (page != <span style="color: blue;">null</span> &amp;&amp; PageTreeLeftMenu.OpenPages.Contains(page.PageLink))</p>
<p style="margin: 0px;"><span style="color: blue;">return</span> <span style="color: #a31515;">&#034;class=\&#034;expanded\&#034;"</span>;</p>
<p style="margin: 0px;"><span style="color: blue;">return</span> <span style="color: blue;">string</span>.Empty;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">}</p>
</div>
<p>Things to notice:</p>
<ul>
<li>LeftmenuPageLink is just an example on how to set the start point for the left menu.</li>
<li><strong>GetExpandedClass </strong>is the method that sets the correct class on the &lt;li&gt;. This is done by checking if the page in the tree is available in PageTree.OpenPages. This is what makes it possible to make the dynamic menu. If the OpenPages method was not available, it would not be possible to highlight the expanded nodes without traversing each node or doing some javascripting.</li>
</ul>
<p>The output should look something like this</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;"> 43</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">div</span> <span style="color: red;">class</span><span style="color: blue;">=&#034;leftcolumn&#034;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 44</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">div</span> <span style="color: red;">class</span><span style="color: blue;">=&#034;leftmenu&#034;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 45</span> <span style="color: green;">&lt;!&#8211; Header &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 46</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 47</span> <span style="color: green;">&lt;!&#8211; Indent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 48</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span> <span style="color: red;">class</span><span style="color: blue;">=&#034;expanded&#034;&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Consulting/&#034;&gt;</span>Consulting<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 49</span> <span style="color: green;">&lt;!&#8211; ExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 50</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 51</span> <span style="color: green;">&lt;!&#8211; Indent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 52</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span> <span style="color: red;">class</span><span style="color: blue;">=&#034;expanded&#034;&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">class</span><span style="color: blue;">=&#034;selected&#034;</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Consulting/Business-Consulting-/&#034;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 53</span> Business Consulting <span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 54</span> <span style="color: green;">&lt;!&#8211; SelectedExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 55</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 56</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Consulting/Project-and-Test-Management/&#034;&gt;</span>Project and Test</p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 57</span> Management<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 58</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 59</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 60</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Consulting/IT-Consulting/&#034;&gt;</span>IT Consulting<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 61</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 62</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 63</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Consulting/Application-Development/&#034;&gt;</span>Application Development<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 64</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 65</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 66</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 67</span> <span style="color: green;">&lt;!&#8211; UnIndent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 68</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 69</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/&#034;&gt;</span>Solutions<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 70</span> <span style="color: green;">&lt;!&#8211; ExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 71</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 72</span> <span style="color: green;">&lt;!&#8211; Indent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 73</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/ERP/&#034;&gt;</span>ERP<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 74</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 75</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 76</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/Content-Management/&#034;&gt;</span>Content Management<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 77</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 78</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 79</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/Oil-and-Gas/&#034;&gt;</span>Oil and Gas<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 80</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 81</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 82</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/Industry/&#034;&gt;</span>Industry<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 83</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 84</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 85</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/E-Business/&#034;&gt;</span>E-Business<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 86</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 87</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 88</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/Banking&#8211;Finance-Suite/&#034;&gt;</span>Banking <span style="color: red;">&amp;amp;</span> Finance</p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 89</span> Suite<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 90</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 91</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 92</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Solutions/Public-Sector-Suite/&#034;&gt;</span>Public Sector Suite<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 93</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 94</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 95</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 96</span> <span style="color: green;">&lt;!&#8211; UnIndent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 97</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 98</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Outsourcing/&#034;&gt;</span>Outsourcing<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 99</span> <span style="color: green;">&lt;!&#8211; ExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 100</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 101</span> <span style="color: green;">&lt;!&#8211; Indent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 102</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Outsourcing/ITO/&#034;&gt;</span>ITO<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 103</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 104</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 105</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/Outsourcing/Applications-Management/&#034;&gt;</span>Applications Management<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 106</span> <span style="color: green;">&lt;!&#8211; ExpandedItem &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 107</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 108</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 109</span> <span style="color: green;">&lt;!&#8211; UnIndent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 110</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 111</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/TestTest/&#034;&gt;</span>TestTest<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 112</span> <span style="color: green;">&lt;!&#8211; ExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 113</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 114</span> <span style="color: blue;">&lt;</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;&lt;</span><span style="color: #a31515;">a</span> <span style="color: red;">href</span><span style="color: blue;">=&#034;/en/TestTestTest/&#034;&gt;</span>TestTestTest<span style="color: blue;">&lt;/</span><span style="color: #a31515;">a</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 115</span> <span style="color: green;">&lt;!&#8211; ExpandedTop &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 116</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">li</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 117</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">ul</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 118</span> <span style="color: green;">&lt;!&#8211; UnIndent &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 119</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 120</span> <span style="color: green;">&lt;!&#8211; Footer &#8211;&gt;</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;"> 121</span> <span style="color: blue;">&lt;/</span><span style="color: #a31515;">div</span><span style="color: blue;">&gt;</span></p>
</div>
<p>The result will look something like this:</p>
<p style="text-align: center;"><a href="http://hamang.net/wp-content/uploads/2010/02/leftmenu1.jpg"><img class="size-full wp-image-202 aligncenter" title="leftmenu1" src="http://hamang.net/wp-content/uploads/2010/02/leftmenu1.jpg" alt="" width="194" height="469" /></a></p>
<p>After adding the Accordion script, the Top items should collapse and only the expanded section should be visible. When moving the mouse over another section it should expand, but not highlight. The final result will look something like this.<br />
 <a href="http://hamang.net/wp-content/uploads/2010/02/leftmenu2.jpg"><img class="aligncenter size-full wp-image-203" title="leftmenu2" src="http://hamang.net/wp-content/uploads/2010/02/leftmenu2.jpg" alt="" width="194" height="250" /></a></p>
<h3>Conclusion</h3>
<p>Using dynamic menus could give the visitor a better experience. Whether its an Accordion panel or some other fancy scripted menu doesn&#039;t matter. Anyway you will have to dump the whole tree to a certain level (2 levels in this example) and set the correct classes on the elements to get the styling correct. The magic is the &#034;PageTree.OpenPages&#034; method which helps a lot in this scenario.</p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2010/02/10/creating-dynamic-menus-in-episerver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ie7 bug &#8211; Popup blocker prevents clicking dropdown lists.</title>
		<link>http://hamang.net/2009/02/24/ie7-bug-popup-blocker-prevent-clicking-dropdown-lists/</link>
		<comments>http://hamang.net/2009/02/24/ie7-bug-popup-blocker-prevent-clicking-dropdown-lists/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 15:40:22 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=194</guid>
		<description><![CDATA[I had a strange experience with IE 7. It was suddenly impossible to click dropdown lists. The popup blocker displayed the toolbar, saying it blocked a popup. The dropdown was from my own code running on localhost, so it was definitely not a popup defined in the event. I am really not sure when this [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-196" title="ie7" src="http://hamang.net/wp-content/uploads/2009/02/ie7.jpg" alt="ie7" width="185" height="110" />I had a strange experience with IE 7. It was suddenly impossible to click dropdown lists. The popup blocker displayed the toolbar, saying it blocked a popup. The dropdown was from my own code running on localhost, so it was definitely not a popup defined in the event. I am really not sure when this happened. Yesterday I installed the <a href="http://finalbuilds.edskes.net/iecollection.htm" target="_blank">Internet Explorer Collection</a>, which is great for testing GUI in different versions of Internet Explorer. This <strong>could</strong> cause the strange behaviour, but I&#039;m really not sure. The collection includes IE 8 Beta, and I have seen others with IE 8 Beta having this problem.</p>
<p>I soon found out other users having this problem and most referred to this <a href="http://www.mydigitallife.info/2006/07/02/internet-explorer-7-pop-up-blocker-blocks-script-generated-drop-down-or-on-page-input-dialog-boxes/" target="_blank">page</a> for a solution. I tried the suggestion on adding localhost to the &#034;trusted sites&#034; and setting security level to medium-low, but that didn&#039;t solve my problem. I then uninstalled the Internet Explorer Collection without any luck. I also tried resetting Internet Explorer; Tools-&gt;Internet options-&gt;Advanced-&gt;Reset&#8230; (button). But again, no luck. Also restarted windows just to be sure.</p>
<p>Only left solution was to remove or <strong>reinstall </strong>IE7. Removing will downgrade to IE 6, which is really not what I want. So I downloaded the IE 7 installer from Microsoft and installed IE7 again (no option in installer to &#034;reinstall&#034;). Restarting windows, and everything was working fine again. Since that was not one of the options in the guide I found (link above), I though it was worth mention it here.</p>
<p>Ok, back to work&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2009/02/24/ie7-bug-popup-blocker-prevent-clicking-dropdown-lists/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Use regular expressions in Visual Studio to clean up code</title>
		<link>http://hamang.net/2009/02/20/use-regular-expressions-in-visual-studio-to-clean-up-code/</link>
		<comments>http://hamang.net/2009/02/20/use-regular-expressions-in-visual-studio-to-clean-up-code/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 12:30:41 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=191</guid>
		<description><![CDATA[This is a reminder to myself. 
Knut, remember that Regular Expressions are very handy to clean up a lot of messy code. 
Here is an example:
The following function call results in a code analysis warning:
DBHelper.SetPropertyFromDB(m_City, dr(&#034;CITY&#034;))
It&#039;s a helper function that returns the typed value from a DBValue. Not really useful these days with NHibernate or [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is a reminder to myself. </em></p>
<p><strong>Knut, remember that Regular Expressions are very handy to clean up a lot of messy code. </strong></p>
<p>Here is an example:<br />
The following function call results in a code analysis warning:</p>
<p style="font-family: Courier New,Courier,mono;">DBHelper.SetPropertyFromDB(m_City, dr(&#034;CITY&#034;))</p>
<p>It&#039;s a helper function that returns the typed value from a DBValue. Not really useful these days with NHibernate or Typed Datasets, but it&#039;s code from an old application. Here is the signature of the code:</p>
<p style="font-family: Courier New,Courier,mono;">Shared Sub SetPropertyFromDB(ByRef pProperty As Object, ByVal value As Object)</p>
<p>The warning reported is:</p>
<p><em>&#034;Warning: Implicit conversion from &#039;Object&#039; to &#039;String&#039; in copying the value of &#039;ByRef&#039; parameter &#039;pProperty&#039; back to the matching argument.&#034;</em></p>
<p>To fix this, I created a new method that returns the correct typed value instead of returning the referenced parameter and marked the old method &#034;Obsolete&#034;:</p>
<p style="font-family: Courier New,Courier,mono;">Public Shared Function GetDBValue(ByVal pProperty As Object, ByVal dbValue As Object) As Object</p>
<p>Now, I had to rewrite all the calls to the function (several hundred calls). This included returning the typed value into the same variable as the first parameter in the function call, like this:</p>
<p style="font-family: Courier New,Courier,mono;">m_City = DBHelper.GetDBValue(m_City, dr(&#034;CITY&#034;))</p>
<p>This is easily achieved by using Regular Expressions in the &#034;Find and Replace&#034; dialog in Visual Studio:</p>
<p>Find What:</p>
<p style="font-family: Courier New,Courier,mono;">DBHelper.SetPropertyFromDB\({.*},</p>
<p>(note: the \ escapes the ( and the expression group is marked by a {})</p>
<p>Replace with:</p>
<p style="font-family: Courier New,Courier,mono;">\1 = DBHelper.GetDBValue(\1,</p>
<p>(note: the \1 will represent the expression group)</p>
<p>Pretty simple, and very powerful  <img src='http://hamang.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2009/02/20/use-regular-expressions-in-visual-studio-to-clean-up-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extend the GridView</title>
		<link>http://hamang.net/2009/02/19/extend-the-gridview/</link>
		<comments>http://hamang.net/2009/02/19/extend-the-gridview/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 10:29:56 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/2009/02/19/extend-the-gridview/</guid>
		<description><![CDATA[The default GridView class has by default a lot of great features. However, some important features are missing. One of the most important is the ability to display the grid even if it is empty.
Here is a great class extending the GridView with some additional features.
http://forums.asp.net/p/1012442/2951765.aspx#2951765
]]></description>
			<content:encoded><![CDATA[<p>The default GridView class has by default a lot of great features. However, some important features are missing. One of the most important is the ability to display the grid even if it is empty.<br />
Here is a great class extending the GridView with some additional features.</p>
<p><a href="http://forums.asp.net/p/1012442/2951765.aspx#2951765" target="_blank">http://forums.asp.net/p/1012442/2951765.aspx#2951765</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2009/02/19/extend-the-gridview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XBOX &#8211; be quiet!</title>
		<link>http://hamang.net/2009/02/03/xbox-be-quiet/</link>
		<comments>http://hamang.net/2009/02/03/xbox-be-quiet/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 12:15:38 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Xbox]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=181</guid>
		<description><![CDATA[I have 3 Xbox 360&#039;s at home. Seems a bit too much, but they have really come down in price, and I use 2 of them as extenders for my Vista Media Center. The biggest problem with the Xbox is the noise it produce. The Media Center box is virtually silent using a mCubed hfx [...]]]></description>
			<content:encoded><![CDATA[<p>I have 3 Xbox 360&#039;s at home. Seems a bit too much, but they have really come down in price, and I use 2 of them as extenders for my Vista Media Center. The biggest problem with the Xbox is the noise it produce. The Media Center box is virtually silent using a <a href="http://www.hfx.at/" target="_blank">mCubed hfx classic</a>, so I want my extenders to be as quiet as possible. I could of course buy some Linksys DMA 2100 extenders, but they do not support VGA out, which is the only input option on my LCD monitor.</p>
<p>I&#039;m using one of the Xboxes in the kitchen, connected to a 15&#034; LCD monitor. The LCD is mounted above the fridge and serves as a kitchen TV. The Xbox is hidden behind a shelf placed above the refrigerator. This is almost in ear height when standing up and makes the noise come out pretty loud.</p>
<p>I read some reviews on the <a href="http://www.lian-li.com/v2/en/microsite6/xb01user01.html" target="_blank">Lian Li PC XB01</a> case and decided to give it a try. Opening the Xbox will void the warranty, so I decided to modify the oldest one, as it no longer has a warranty.</p>
<p>The Lian Li case is pretty large as you can see in the video below.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/kv43YmUxB1Q&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/kv43YmUxB1Q&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>This is mainly because of the large 120mm fan in the back. But it also gives some opportunities regarding further modding and better controlling the noise. You can even put a water cooling system in there. There are dedicated holes in the case for the water tubes.</p>
<p>It was quite tricky to dismount the Xbox, and you need a set of Torx tools (6, 8 and 10) to be able to do the work. Mounting the mainboard and DVD drive in the Lian case was straight forward.</p>
<p><strong>The result </strong></p>
<p>As this mod is only used as a Media Center Extender and not used for playing games at all, I didn&#039;t need the Xbox harddrive. The only noise coming from the case will be the fan. The standard fan which comes with the case is not very silent, but far better than the Xbox fans. I guess I will order a Papst fan to replace the standard fan.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/HP_wmB8vDqU&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/HP_wmB8vDqU&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><em>Standard Xbox 360 Arcade (Falcon chipset)</em><em></em></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Qhf79gF7HVU&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/Qhf79gF7HVU&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><em>Xbox 360 inside Lian Li PC XB01using oem fan (Zephyr chipset)</em></p>
<p>I also found a more extreme cooling solution for even more silent mods. Check out this site, which has an awesome mod: <a href="http://www.silentxbox.com/xbox_eng.php" target="_blank">http://www.silentxbox.com/xbox_eng.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2009/02/03/xbox-be-quiet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web application absolute path</title>
		<link>http://hamang.net/2008/12/17/web-application-absolute-path/</link>
		<comments>http://hamang.net/2008/12/17/web-application-absolute-path/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 13:56:37 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=176</guid>
		<description><![CDATA[Just a reminder on how to get the absolute path for the webapplication in ASP.NET
HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +        VirtualPathUtility.ToAbsolute(HttpContext.Current.Request.ApplicationPath)
This will return http://subdomain.domain.com/applicationname
You can drop those AppSettings with ApplicationPath  
]]></description>
			<content:encoded><![CDATA[<p>Just a reminder on how to get the absolute path for the webapplication in ASP.NET</p>
<p>HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +        VirtualPathUtility.ToAbsolute(HttpContext.Current.Request.ApplicationPath)</p>
<p>This will return http://subdomain.domain.com/applicationname</p>
<p>You can drop those AppSettings with ApplicationPath <img src='http://hamang.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/12/17/web-application-absolute-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using log4net in Web Applications &#8211; a real-life example</title>
		<link>http://hamang.net/2008/12/12/using-log4net-in-web-applications-a-reallife-example/</link>
		<comments>http://hamang.net/2008/12/12/using-log4net-in-web-applications-a-reallife-example/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:30:08 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=164</guid>
		<description><![CDATA[I have seen many different configurations for Log4Net. Log4Net is a very simple, but flexible framework and there are lot of ways to configure it. Here is a real-life example on how we are using in the applications I am working on.
First off, I won&#039;t say that this is the one and only way you [...]]]></description>
			<content:encoded><![CDATA[<p>I have seen many different configurations for Log4Net. Log4Net is a very simple, but flexible framework and there are lot of ways to configure it. Here is a real-life example on how we are using in the applications I am working on.</p>
<p>First off, I won&#039;t say that this is the one and only way you should use Log4Net, but it handles most of the scenarios I can think of.  Some people think that one should not write wrappers for the loggers and use the logging framework directly in the class, but to be honest I like the wrapper because it makes it very simple to use the logging framework without too much knowledge on how it works. I would say that 95% of what is being logged, is typically errors and debug/useful information. I can&#039;t see any problem using a wrapper as I get the information I need from the loggers.</p>
<h3>Goals with this log configuration</h3>
<ul>
<li>Most important is of course logging errors. All errors should be logged.</li>
<li>Errors should be logged in a global file on the server that will role once a day.</li>
<li>Errors should be sent by email.</li>
<li>It should be possible to notify important information by email</li>
<li>It should be easy for the developers to use the logging framework</li>
<li>It should be possible to change log-level without restarting the application</li>
</ul>
<h3>Configuration and setup</h3>
<p>Log4Net consists of only one DLL. Get the latest version and put it in your bin folder. Make a reference to it in the Web Application Project.</p>
<h3>Log4net.config</h3>
<p>Create a new config file in the root of your Web Application. Name it Log4Net.config and paste the following code:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;}??\fs20 \cf1 &lt;?\cf3 xml\cf1  \cf4 version\cf1 =\cf0 "\cf1 1.0\cf0 "\cf1  \cf4 encoding\cf1 =\cf0 "\cf1 utf-8\cf0 "\cf1  ?&gt;\par ??&lt;\cf3 configuration\cf1 &gt;\par ??    &lt;\cf3 configSections\cf1 &gt;\par ??        &lt;\cf3 section\cf1  \cf4 name\cf1 =\cf0 "\cf1 log4net\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Config.Log4NetConfigurationSectionHandler, log4net\cf0 "\cf1  /&gt;\par ??    &lt;/\cf3 configSections\cf1 &gt;\par ??    &lt;\cf3 log4net\cf1 &gt;\par ??        &lt;\cf3 appender\cf1  \cf4 name\cf1 =\cf0 "\cf1 RollingLogFileAppender\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Appender.RollingFileAppender\cf0 "\cf1 &gt;\par ??            &lt;\cf3 threshold\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 file\cf1  \cf4 value\cf1 =\cf0 "\cf1 Log\\[applicationname].log\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appendToFile\cf1  \cf4 value\cf1 =\cf0 "\cf1 true\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 rollingStyle\cf1  \cf4 value\cf1 =\cf0 "\cf1 Date\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 datePattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 '.'yyyyMMdd'.log'\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 layout\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Layout.PatternLayout\cf0 "\cf1 &gt;\par ??                &lt;\cf3 conversionPattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 %date [%thread] %-5level %logger %X\{user\} %X\{url\} - %message%newline\cf0 "\cf1  /&gt;\par ??            &lt;/\cf3 layout\cf1 &gt;\par ??        &lt;/\cf3 appender\cf1 &gt;\par ??        &lt;\cf3 appender\cf1  \cf4 name\cf1 =\cf0 "\cf1 SmtpAppenderError\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Appender.SmtpAppender\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set threshold for this appender\cf1  &gt;\par ??            &lt;\cf3 threshold\cf1  \cf4 value\cf1 =\cf0 "\cf1 WARN\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 to\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 from\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 subject\cf1  \cf4 value\cf1 =\cf0 "\cf1 Error from [applicationname]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 smtpHost\cf1  \cf4 value\cf1 =\cf0 "\cf1 [100.100.100.100]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 bufferSize\cf1  \cf4 value\cf1 =\cf0 "\cf1 1\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 lossy\cf1  \cf4 value\cf1 =\cf0 "\cf1 false\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 layout\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Layout.PatternLayout\cf0 "\cf1 &gt;\par ??                &lt;\cf3 conversionPattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 %date %-5level %logger %X\{user\} %X\{url\} - %message%newline\cf0 "\cf1  /&gt;\par ??            &lt;/\cf3 layout\cf1 &gt;\par ??        &lt;/\cf3 appender\cf1 &gt;\par ??        &lt;\cf3 appender\cf1  \cf4 name\cf1 =\cf0 "\cf1 SmtpAppenderNotify\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Appender.SmtpAppender\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set threshold for this appender\cf1  &gt;\par ??            &lt;\cf3 threshold\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 to\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 from\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 subject\cf1  \cf4 value\cf1 =\cf0 "\cf1 Error from [applicationname]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 smtpHost\cf1  \cf4 value\cf1 =\cf0 "\cf1 [100.100.100.100]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 bufferSize\cf1  \cf4 value\cf1 =\cf0 "\cf1 1\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 lossy\cf1  \cf4 value\cf1 =\cf0 "\cf1 false\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 layout\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Layout.PatternLayout\cf0 "\cf1 &gt;\par ??                &lt;\cf3 conversionPattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 %date - %message%newline\cf0 "\cf1  /&gt;\par ??            &lt;/\cf3 layout\cf1 &gt;\par ??        &lt;/\cf3 appender\cf1 &gt;\par ??        &lt;\cf3 root\cf1 &gt;\par ??            &lt;\cf3 level\cf1  \cf4 value\cf1 =\cf0 "\cf1 Error\cf0 "\cf1  /&gt;        \par ??        &lt;/\cf3 root\cf1 &gt;\par ??        &lt;\cf3 logger\cf1  \cf4 name\cf1 =\cf0 "\cf1 Application\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set level for this logger\cf1  &gt;\par ??            &lt;\cf3 level\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 RollingLogFileAppender\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 SmtpAppenderError\cf0 "\cf1  /&gt;\par ??        &lt;/\cf3 logger\cf1 &gt;\par ??        &lt;\cf3 logger\cf1  \cf4 name\cf1 =\cf0 "\cf1 Notify\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set level for this logger\cf1  &gt;\par ??            &lt;\cf3 level\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 RollingLogFileAppender\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 SmtpAppenderNotify\cf0 "\cf1  /&gt;\par ??        &lt;/\cf3 logger\cf1 &gt;\par ??    &lt;/\cf3 log4net\cf1 &gt;\par ??&lt;/\cf3 configuration\cf1 &gt;} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<pre style="margin: 0px;"><span style="color: blue;">&lt;?</span><span style="color: #a31515;">xml</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span style="color: blue;"> </span><span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span style="color: blue;"> ?&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">configSections</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net</span>"<span style="color: blue;"> </span><span style="color: red;">
        type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Config.Log4NetConfigurationSectionHandler, log4net</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;/</span><span style="color: #a31515;">configSections</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">log4net</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">appender</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">RollingLogFileAppender</span>"<span style="color: blue;">
            </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Appender.RollingFileAppender</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">threshold</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">file</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Log\[applicationname].log</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appendToFile</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">rollingStyle</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Date</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">datePattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">'.'yyyyMMdd'.log'</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">layout</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Layout.PatternLayout</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">                &lt;</span><span style="color: #a31515;">conversionPattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">%date [%thread] %-5level
                  %logger %X{user} %X{url} - %message%newline</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;/</span><span style="color: #a31515;">layout</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">appender</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">appender</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderError</span>"<span style="color: blue;"> </span><span style="color: red;">
                  type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Appender.SmtpAppender</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set threshold for this appender</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">threshold</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">ERROR</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">to</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">from</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">subject</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Error from [applicationname]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">smtpHost</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[100.100.100.100]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">bufferSize</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">1</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">lossy</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">false</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">layout</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Layout.PatternLayout</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">                &lt;</span><span style="color: #a31515;">conversionPattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">%date %-5level
                %logger %X{user} %X{url} - %message%newline</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;/</span><span style="color: #a31515;">layout</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">appender</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">appender</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderNotify</span>"<span style="color: blue;">
                  </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Appender.SmtpAppender</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set threshold for this appender</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">threshold</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">to</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">from</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">subject</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Error from [applicationname]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">smtpHost</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[100.100.100.100]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">bufferSize</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">1</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">lossy</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">false</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">layout</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Layout.PatternLayout</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">                &lt;</span><span style="color: #a31515;">conversionPattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">%date - %message%newline</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;/</span><span style="color: #a31515;">layout</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">appender</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">root</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">level</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Error</span>"<span style="color: blue;"> /&gt;        </span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">root</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">logger</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Application</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set level for this logger</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">level</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">RollingLogFileAppender</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderError</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">logger</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">logger</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Notify</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set level for this logger</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">level</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">RollingLogFileAppender</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderNotify</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">logger</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;/</span><span style="color: #a31515;">log4net</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;
</span></pre>
</div>
<p>Some comments on the Log4net.config file:</p>
<ul>
<li>The RollingFileAppender is great for rolling the logfile once a day.
<ul>
<li>It has a threshold of INFO, meaning it will log anything from the application except debug information</li>
<li>The logfiles are created in a subdirectory of web root. This should be changed on the production server to not expose information about the application.</li>
<li>The datePattern is specifying how the rolling files are named. The current day will be named &#034;applicationname.log&#034; and yesterdays file will be named &#034;applicationname.log.20081211.log&#034;. The rolling file extension (.log)  makes it easy to open the file in the same editor as the current log. All files will be sorted correctly when using the ISO style date in the filename.</li>
<li>In the conversionPattern you will see two speacial entries with the following format: %X{name}. These are custom formats which can be used for special purposes. This configuration adds the authenticated username and the url which fails if there is an error. This is useful information.</li>
</ul>
</li>
<li>The SmtpAppenders are used for sending emails. It&#039;s really not my favourite configuration, spamming the developers or some other people with emails when some errors occur, but some like it.
<ul>
<li>The threshold is different for the two SmtpAppenders, as is the subject of the email.</li>
<li>The buffersize is set to 1 in the example, meaning that the email is sent right away when an error occur. Increasing the buffer will hold the email until the buffer is reached. This can be useful on the production server, especially for the Notify appender as it is probably not that important to notify right away.</li>
<li>Lossy is set to false, also to send the email right away. It is possible to hold the email until an evaluator is triggered, for instance when a error occurs. Setting lossy to true requires an evaluator.</li>
<li>It is possible to add filters to the appenders to determine which emails should be sent and which to drop.</li>
</ul>
</li>
<li>There are two specific loggers that the application will use. The root logger can be used to log 3.party libraries also using Log4Net. I like to use specific loggers in the application and enabling the root logger if I am tracing an error where I need more information from 3.party libraries, ie. NHibernate or other frameworks using Log4net. Remember to set the level for the logger. If not set, the default level is WARN, which means INFO messages will not be logged.</li>
</ul>
<p>To be able to use the Log4Net.config file instead of putting everything into web.config, you will need to add the following line to AssemblyInfo.vb:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue255;}??\fs20 &lt;Assembly: log4net.Config.XmlConfigurator(ConfigFile:=\cf3 "Log4Net.config"\cf0 , Watch:=\cf4 True\cf0 )&gt; } --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;">&lt;Assembly: log4net.Config.XmlConfigurator(ConfigFile:=<span style="color: #a31515;">"Log4Net.config"</span>, Watch:=<span style="color: blue;">True</span>)&gt;</pre>
</div>
<p>The advantage of separating the Log4Net configuration is that it is possible to change the configuration of the logging without restarting the application by changing web.config.  It also gives an better overview of the configuration, not having to browse through web.config to find the logging configuration.</p>
<h3>Logging unhandled errors</h3>
<p>All unhandled errors should be logged, which is pretty easy to achieve in web applications. Here is the Global.asax file:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf1 Imports\cf0  System.Web\par ??\cf1 Imports\cf0  log4net\par ??\cf1 Imports\cf0  MainLib\par ??\par ??\cf1 Public\cf0  \cf1 Class\cf0  [Global]\par ??    \cf1 Inherits\cf0  System.Web.HttpApplication\par ??\par ??    \cf1 Sub\cf0  Application_Start(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the application is started\par ??\cf0         \cf4 ' Initialize the logger in this context.\par ??\cf0         LogManager.GetLogger(\cf1 Me\cf0 .GetType)\par ??        LogHandler.LogInfo(\cf5 "============================"\cf0 , LogHandler.LogType.General)\par ??        LogHandler.LogInfo(\cf5 "    Starting application"\cf0 , LogHandler.LogType.General)\par ??        LogHandler.LogInfo(\cf5 "============================"\cf0 , LogHandler.LogType.General)\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Session_Start(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the session is started\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_BeginRequest(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires at the beginning of each request\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_AuthenticateRequest(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires upon attempting to authenticate the use\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_Error(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when an error occurs\par ??\cf0         LogHandler.LogError(\cf5 "Unhandled exception occured!"\cf0 , HttpContext.Current.User, HttpContext.Current.User, HttpContext.Current.Server.GetLastError())\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Session_End(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the session ends\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_End(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the application ends\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??End\cf0  \cf1 Class\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> System.Web</pre>
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> log4net</pre>
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> MainLib</pre>
<pre style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Class</span> [Global]</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Inherits</span> System.Web.HttpApplication</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_Start(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the application is started</span></pre>
<pre style="margin: 0px;">        <span style="color: green;">' Initialize the logger in this context.</span></pre>
<pre style="margin: 0px;">        LogManager.GetLogger(<span style="color: blue;">Me</span>.GetType)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"============================"</span>, LogHandler.LogType.General)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"    Starting application"</span>, LogHandler.LogType.General)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"============================"</span>, LogHandler.LogType.General)</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Session_Start(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the session is started</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_BeginRequest(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires at the beginning of each request</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_AuthenticateRequest(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires upon attempting to authenticate the use</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_Error(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when an error occurs</span></pre>
<pre style="margin: 0px;">        LogHandler.LogError(<span style="color: #a31515;">"Unhandled exception occured!"</span>,
        HttpContext.Current.User, HttpContext.Current.Request.Url,
        HttpContext.Current.Server.GetLastError())</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Session_End(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the session ends</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_End(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the application ends</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Class</span></pre>
</div>
<p>Comments on Global.asax</p>
<ul>
<li>I have added some information logging in the Application_Start event. This will trigger every time the applications starts or recycles. If this occurs often you probably have some problems with resources on the server, ie. too little memory available for the application.</li>
<li>Application_Error occurs every time an unhandled error occurs. Use this to log all errors not logged elsewhere.</li>
<li>I have to initialize the logging framework in Application_Start by calling
<p style="margin: 0px;">LogManager.GetLogger(<span style="color: blue;">Me</span>.GetType).  I&#039;m not sure whether this is a bug or by design. It is not possible to let the LogHandler do the initialization. LogHandler is a wrapper class located in another assembly, maybe that is a problem, without really knowing why. LogManager is a class in Log4Net.</p>
</li>
</ul>
<h3>The LogHandler class</h3>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf1 Imports\cf0  System.Security.Principal\par ??\cf1 Imports\cf0  log4net\par ??\par ??\par ??\cf1 Public\cf0  \cf1 Class\cf0  LogHandler\par ??    \cf1 Const\cf0  _defaultApplicationLogger \cf1 As\cf0  \cf1 String\cf0  = \cf4 "Application"\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Enum\cf0  LogType\par ??        General\par ??        Notify\par ??    \cf1 End\cf0  \cf1 Enum\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogError(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri, \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 If\cf0  \cf1 Not\cf0  [error].InnerException \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 Then\par ??\cf0             [error] = [error].InnerException\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf5 'set user to log4net context, so we can use %X\{user\} in the appenders\par ??\cf0         \cf1 If\cf0  \cf1 Not\cf0  user \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 AndAlso\cf0  user.Identity.IsAuthenticated \cf1 Then\par ??\cf0             MDC.[Set](\cf4 "user"\cf0 , user.Identity.Name)\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf5 'set url to log4net context, so we can use %X\{url\} in the appenders\par ??\cf0         MDC.[Set](\cf4 "url"\cf0 , url.ToString())\par ??\par ??        \cf1 If\cf0  logger.IsErrorEnabled \cf1 Then\par ??\cf0             logger.Error(message, [error])\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogInfo(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  type \cf1 As\cf0  LogType)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = \cf1 Nothing\par ??\cf0         \cf1 If\cf0  type = LogType.Notify \cf1 Then\par ??\cf0             logger = LogManager.GetLogger(LogType.Notify.ToString)\par ??        \cf1 Else\par ??\cf0             logger = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf1 If\cf0  logger.IsInfoEnabled \cf1 Then\par ??\cf0             logger.Info(message)\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??End\cf0  \cf1 Class\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf1 Imports\cf0  System.Security.Principal\par ??\cf1 Imports\cf0  log4net\par ??\par ??\cf1 Public\cf0  \cf1 Class\cf0  LogHandler\par ??    \cf1 Const\cf0  _defaultApplicationLogger \cf1 As\cf0  \cf1 String\cf0  = \cf4 "Application"\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Enum\cf0  LogType\par ??        General\par ??        Notify\par ??    \cf1 End\cf0  \cf1 Enum\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogError(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 If\cf0  \cf1 Not\cf0  [error].InnerException \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 Then\par ??\cf0             [error] = [error].InnerException\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf1 If\cf0  logger.IsErrorEnabled \cf1 Then\par ??\cf0             logger.Error(message, [error])\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogError(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , _\par ??                                \cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri, _\par ??                                \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        SetOptionalParametersOnLogger(user, url)\par ??        LogError(message, [error])\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogInfo(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  type \cf1 As\cf0  LogType)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = \cf1 Nothing\par ??\cf0         \cf1 If\cf0  type = LogType.Notify \cf1 Then\par ??\cf0             logger = LogManager.GetLogger(LogType.Notify.ToString)\par ??        \cf1 Else\par ??\cf0             logger = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0         \cf1 If\cf0  logger.IsInfoEnabled \cf1 Then\par ??\cf0             logger.Info(message)\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogWarning(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 If\cf0  \cf1 Not\cf0  [error].InnerException \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 Then\par ??\cf0             [error] = [error].InnerException\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0         \cf1 If\cf0  logger.IsWarnEnabled \cf1 Then\par ??\cf0             logger.Warn(message, [error])\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogWarning(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , _\par ??                                 \cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri, _\par ??                                 \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        SetOptionalParametersOnLogger(user, url)\par ??        LogWarning(message, [error])\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Private\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  SetOptionalParametersOnLogger(\cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri)\par ??        \cf5 'set user to log4net context, so we can use %X\{user\} in the appenders\par ??\cf0         \cf1 If\cf0  \cf1 Not\cf0  user \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 AndAlso\cf0  user.Identity.IsAuthenticated \cf1 Then\par ??\cf0             MDC.[Set](\cf4 "user"\cf0 , user.Identity.Name)\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf5 'set url to log4net context, so we can use %X\{url\} in the appenders\par ??\cf0         MDC.[Set](\cf4 "url"\cf0 , url.ToString())\par ??    \cf1 End\cf0  \cf1 Sub\par ??End\cf0  \cf1 Class\par ??\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> System.Security.Principal</pre>
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> log4net</pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Class</span> LogHandler</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Const</span> _defaultApplicationLogger <span style="color: blue;">As</span> <span style="color: blue;">String</span> = <span style="color: #a31515;">"Application"</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Enum</span> LogType</pre>
<pre style="margin: 0px;">        General</pre>
<pre style="margin: 0px;">        Notify</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Enum</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogError(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> logger <span style="color: blue;">As</span> ILog = LogManager.GetLogger(_defaultApplicationLogger)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> <span style="color: blue;">Not</span> [error].InnerException <span style="color: blue;">Is</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            [error] = [error].InnerException</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> logger.IsErrorEnabled <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger.Error(message, [error])</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogError(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, _</pre>
<pre style="margin: 0px;">                                <span style="color: blue;">ByVal</span> user <span style="color: blue;">As</span> IPrincipal, <span style="color: blue;">ByVal</span> url <span style="color: blue;">As</span> Uri, _</pre>
<pre style="margin: 0px;">                                <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;">        SetOptionalParametersOnLogger(user, url)</pre>
<pre style="margin: 0px;">        LogError(message, [error])</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogInfo(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> type <span style="color: blue;">As</span> LogType)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> logger <span style="color: blue;">As</span> ILog = <span style="color: blue;">Nothing</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> type = LogType.Notify <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger = LogManager.GetLogger(LogType.Notify.ToString)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Else</span></pre>
<pre style="margin: 0px;">            logger = LogManager.GetLogger(_defaultApplicationLogger)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> logger.IsInfoEnabled <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger.Info(message)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogWarning(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> logger <span style="color: blue;">As</span> ILog = LogManager.GetLogger(_defaultApplicationLogger)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> <span style="color: blue;">Not</span> [error].InnerException <span style="color: blue;">Is</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            [error] = [error].InnerException</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> logger.IsWarnEnabled <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger.Warn(message, [error])</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogWarning(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, _</pre>
<pre style="margin: 0px;">                                 <span style="color: blue;">ByVal</span> user <span style="color: blue;">As</span> IPrincipal, <span style="color: blue;">ByVal</span> url <span style="color: blue;">As</span> Uri, _</pre>
<pre style="margin: 0px;">                                 <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;">        SetOptionalParametersOnLogger(user, url)</pre>
<pre style="margin: 0px;">        LogWarning(message, [error])</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Private</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> SetOptionalParametersOnLogger(<span style="color: blue;">ByVal</span> user <span style="color: blue;">As</span> IPrincipal, <span style="color: blue;">ByVal</span> url <span style="color: blue;">As</span> Uri)</pre>
<pre style="margin: 0px;">        <span style="color: green;">'set user to log4net context, so we can use %X{user} in the appenders</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> <span style="color: blue;">Not</span> user <span style="color: blue;">Is</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">AndAlso</span> user.Identity.IsAuthenticated <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            MDC.[Set](<span style="color: #a31515;">"user"</span>, user.Identity.Name)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">        <span style="color: green;">'set url to log4net context, so we can use %X{url} in the appenders</span></pre>
<pre style="margin: 0px;">        MDC.[Set](<span style="color: #a31515;">"url"</span>, url.ToString())</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Class</span></pre>
<pre style="margin: 0px;"></pre>
</div>
</div>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"></div>
<p>Comments on LogHandler</p>
<ul>
<li>It&#039;s a pretty simple class which is easy to use. I could have added more wrapper methods with overload</li>
<li>The LogType enum defines whether the message should be notified (emailed) or not.</li>
<li>If I forget to set the level on the logger in the Log4Net.config, the logger.IsInfoEnabled will return false.</li>
<li>I am using the MDC class in the Log4Net framework to add the custom entries in the logged message for user and url (see Log4Net.config above)</li>
</ul>
<h3>Handling an error and notifying with success</h3>
<p>Sometimes when you know what could go wrong and you want to display a nice error message to the user, you could handle the error and display an errormessage to the user.</p>
<p>Example:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red163\green21\blue21;}??\fs20     \cf3 Private\cf0  \cf3 Function\cf0  CreateUser() \cf3 As\cf0  User\par ??        \cf3 Dim\cf0  userName \cf3 As\cf0  \cf3 String\cf0  = TextBoxUserName.Text\par ??        \cf3 Dim\cf0  password \cf3 As\cf0  \cf3 String\cf0  = TextBoxPassword.Text\par ??        \cf3 Try\par ??\cf0             \cf3 Dim\cf0  user \cf3 As\cf0  \cf3 New\cf0  User(userName, password)\par ??            LogHandler.LogInfo(\cf4 "Yahoo! User with username "\cf0  &amp; userName &amp; \cf4 " created."\cf0 , LogHandler.LogType.Notify)\par ??            \cf3 Return\cf0  user\par ??        \cf3 Catch\cf0  iunex \cf3 As\cf0  InvalidUserNameException\par ??            Tools.AlertError(Page, iunex)\par ??            LogHandler.LogError(\cf4 "Error creating user with username "\cf0  &amp; userName, HttpContext.Current.User, HttpContext.Current.Request.Url, iunex)\par ??        \cf3 Catch\cf0  ipex \cf3 As\cf0  InvalidPasswordException\par ??            Tools.AlertError(Page, iunex)\par ??            LogHandler.LogError(\cf4 "Error creating user with password "\cf0  &amp; password, HttpContext.Current.User, HttpContext.Current.Request.Url, ipex)\par ??        \cf3 End\cf0  \cf3 Try\par ??\cf0     \cf3 End\cf0  \cf3 Function\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<pre style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Function</span> CreateUser() <span style="color: blue;">As</span> User</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Dim</span> userName <span style="color: blue;">As</span> <span style="color: blue;">String</span> = TextBoxUserName.Text</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Dim</span> password <span style="color: blue;">As</span> <span style="color: blue;">String</span> = TextBoxPassword.Text</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Try</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> user <span style="color: blue;">As</span> <span style="color: blue;">New</span> User(userName, password)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"Yahoo! User with username "</span> &amp; userName &amp; <span style="color: #a31515;">" created."</span>,
                           LogHandler.LogType.Notify)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Return</span> user</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Catch</span> iunex <span style="color: blue;">As</span> InvalidUserNameException</pre>
<pre style="margin: 0px;">        PageTools.DisplayError(Page, iunex)</pre>
<pre style="margin: 0px;">        LogHandler.LogWarning(<span style="color: #a31515;">"Error creating user with username "</span> &amp; userName, iunex)</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Catch</span> ipex <span style="color: blue;">As</span> InvalidPasswordException</pre>
<pre style="margin: 0px;">        PageTools.DisplayError(Page, ipex)</pre>
<pre style="margin: 0px;">        LogHandler.LogWarning(<span style="color: #a31515;">"Error creating user with password "</span> &amp; password, ipex)</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Try
    Return Nothing</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Function</span></pre>
</div>
<p>Comments on CreateUser:</p>
<ul>
<li>If successful, a notification is sent by email by using the LogInfo method and using LogHandler.Logtype.Notify</li>
<li>The User class will throw InvalidUserNameException or InvalidPasswordException in the credentials are invalid. I wish to display the errors to the user instead of displaying a general error page. In real life I would probably use some validation before calling the User constructor, but this is only an example.  <img src='http://hamang.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>In addition to displaying the error to the user, the error is logged as a warning.This means it will be logged, but no email will be sent to the mailbox as this is not an error in the application.</li>
<li>All other exceptions raised when creating the user will be caught in Application_Error in Global.asax and logged there.</li>
</ul>
<h3>Loginformation</h3>
<p>Ok, now I have all the code I need to do decent logging. So what do I expect to see in the logfiles?</p>
<p>When building the application in DEBUG mode I will see the following in the logfile:</p>
<pre>2008-12-11 16:56:24,453 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:56:24,468 [14] INFO  Application (null) (null) -     Starting application
2008-12-11 16:56:24,468 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:56:25,937 [14] WARN Application 3DX5G3J\knuth http://localhost/fdb/default.aspx -
                                  Error creating user with username Knut Hamang
DAL.InvalidUserNameException: Username is already in use! Please select another username.
   at DAL.User..ctor(String username, String password) in C:\Knut\code\Repository\Internal_Systems\fdb\trunk\DAL\User.vb:line 97
   at fdb.default.CreateUser() in C:\Knut\code\Repository\Internal_Systems\fdb\trunk\Web\default.aspx.vb:line 69</pre>
<p>Building in RELEASE  mode I get the following information:</p>
<pre>2008-12-11 16:59:21,406 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:59:21,421 [14] INFO  Application (null) (null) -     Starting application
2008-12-11 16:59:21,421 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:59:22,812 [14] WARN Application 3DX5G3J\knuth http://localhost/fdb/default.aspx -
                             Error creating user with username Knut Hamang
DAL.InvalidUserNameException: Username is already in use! Please select another username.
   at DAL.User..ctor(String username, String password)
   at fdb.default.CreateUser()</pre>
<p>The difference is the stacktrace. I get the stacktrace in both cases, but I also get the line numbers in DEBUG mode. I can still read the trace and locate the method in the file that throws the error. The conclusion is that I get enough information to trace and fix the error, if there is one.</p>
<p>Please leave any comments on the configuration, and feel free to discuss different logging strategies for Web Applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/12/12/using-log4net-in-web-applications-a-reallife-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>bug: VS 2008 &#8211; Web Application Project opened as Web Site</title>
		<link>http://hamang.net/2008/11/03/bug-vs-2008-web-application-project-opened-as-web-site/</link>
		<comments>http://hamang.net/2008/11/03/bug-vs-2008-web-application-project-opened-as-web-site/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 12:44:28 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=153</guid>
		<description><![CDATA[I just bumped into a weird Visual Studio (aka. Vicious Studio)  bug. Not the first, but this is a pretty annoying one. I have taken an old .NET 1.1 Web application and converted it to .NET 3.5 using the VS Conversion Wizard. Everything seems ok, and I convert to Web Site to a Web Application [...]]]></description>
			<content:encoded><![CDATA[<p>I just bumped into a weird Visual Studio (aka. Vicious Studio)  bug. Not the first, but this is a pretty annoying one. I have taken an old .NET 1.1 Web application and converted it to .NET 3.5 using the VS Conversion Wizard. Everything seems ok, and I convert to Web Site to a Web Application Project. No problems so far. I fix some issues, close the solution, do some other stuff. Some days later I open the solution again. I then have about 200 errors and the Web Application Project is opened as a Web Site. Also the designer and resx files are not connected to the asp and codebehind files:</p>
<p><a href="http://hamang.net/wp-content/uploads/2008/11/proj_err.png"><img class="size-full wp-image-155 alignnone" title="disconnected files" src="http://hamang.net/wp-content/uploads/2008/11/proj_err.png" alt="" width="255" height="81" /></a></p>
<div style="clear:both;">It&#039;s not possible to change the project type in Visual Studio, as the project does not have a &#034;properties&#034; context menu item. The only option in the context menu is &#034;property pages&#034; as with regular web sites. Visual Studio actually thinks it&#039;s a Web Site and not a Web Application project anymore. The other missing context menu option is the &#034;Convert to Web Application&#034;. So Visual Studio thinks it&#039;s a Web Site that cannot be converted to a Web Application Project. Not surprisingly as I converted the Web Site to a Web Application Project right after the Conversion Wizard.</p>
<p>Ok, I have to start digging into the project and solution files. Comparing them to other solutions using Web Application project files, I can&#039;t seem to find anything suspicious. After some googling with no result, I decide to stare at the screen for a while and use WinMerge to determine what the difference might be. Suddenly I find one minor difference:</p>
<p>The solution file that works:</p>
<p><em>Project(&#034;{F184B08F-C81C-45F6-A57F-5ABD9991F28F}&#034;) = &#034;Clock&#034;, &#034;Clock.vbproj&#034;, &#034;{3B3D0F02-D310-4BFB-83AD-F62758BB8624}&#034;</em></p>
<p>The one that fails:</p>
<p><em>Project(&#034;{F184B08F-C81C-45F6-A57F-5ABD9991F28F}&#034;) = &#034;Calendar&#034;, &#034;Calendar\&#034;, &#034;{7B411329-B1CB-457F-A954-898DX16B85A6}&#034;</em></p>
<p>That&#039;s it. The Calendar project reference is missing the whole path to the project file. When i change it to:</p>
<p><em>Project(&#034;{F184B08F-C81C-45F6-A57F-5ABD9991F28F}&#034;) = &#034;Calendar&#034;, &#034;<strong>Calendar\Calendar.vbproj</strong>&#034;, &#034;{7B411329-B1CB-457F-A954-898DX16B85A6}&#034;</em></p>
<p>it opens as a Web Application Project, and now the resx and designer files are properly connected:</p></div>
<p><a href="http://hamang.net/wp-content/uploads/2008/11/proj_ok.png"><img class="alignnone size-full wp-image-156" title="files connected" src="http://hamang.net/wp-content/uploads/2008/11/proj_ok.png" alt="" width="248" height="96" /></a></p>
<div style="clear:both;">There might be other issues causing this behaviour, but at least this solved my problem. This is just the everyday life using Visual Studio. Actually I think it&#039;s a great IDE, but there are some strange behaviours now and then.</div>
<div style="clear:both;"></div>
<div style="clear:both;"><strong>Update </strong>- In some occasions you might wan&#039;t to remove the .webinfo file. This file can be causing this behaviour.  Just remove it and instead set the startup path for your application in properties for the Web Application project.</div>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/11/03/bug-vs-2008-web-application-project-opened-as-web-site/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>New version of the Silverlight Calendar</title>
		<link>http://hamang.net/2008/10/03/new-version-of-the-silverlight-calendar/</link>
		<comments>http://hamang.net/2008/10/03/new-version-of-the-silverlight-calendar/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 13:36:46 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=144</guid>
		<description><![CDATA[Some time ago, I wrote a birthday calendar in Silverlight 1.0. It was purely JavaScript and somewhat restricted because of that. Later I upgraded it to Silverlight 1.1, the first version of Silverlight that used managed code. Silverlight 1.1 is now Silverlight 2.0, but there has been a lot of changes between those version.
So here [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I wrote a <a href="/2008/01/29/silverligthcalendar/">birthday calendar</a> in Silverlight 1.0. It was purely JavaScript and somewhat restricted because of that. Later I upgraded it to Silverlight 1.1, the first version of Silverlight that used managed code. Silverlight 1.1 is now Silverlight 2.0, but there has been a lot of changes between those version.<br />
So here is the latest version compatible With Silverlight 2.0 Beta 2. I also added <a href="http://blogs.msdn.com/timrule/archive/2008/04/29/innerglow-effect-for-silverlight-2-beta-1.aspx" target="_blank">Tim Rule&#039;s excellent glowing and shadow effects</a>, which are just awesome!</p>
<p>Download it <a href="/files/SilverlightCalendar2.zip">here</a>.</p>
<p><a href="http://hamang.net/wp-content/uploads/2008/10/calendar2_2.jpg"><img class="alignnone size-medium wp-image-145" title="calendar Silverlight 2 Beta 2" src="http://hamang.net/wp-content/uploads/2008/10/calendar2_2-500x312.jpg" alt="" width="500" height="312" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/10/03/new-version-of-the-silverlight-calendar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moving to WordPress</title>
		<link>http://hamang.net/2008/09/18/moving-to-wordpress/</link>
		<comments>http://hamang.net/2008/09/18/moving-to-wordpress/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 07:52:55 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://hamang.net/wp/?p=126</guid>
		<description><![CDATA[I have been using Mambo/Joomla for quite some time and have realized that it&#039;s not ideal for blogging. I decided to go with a real blogging engine, like WordPress. It&#039;s really neat and easy to use and has a lot of plug-ins and features. I migrated all my joomla content with a script and it [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="WordPress" src="http://s.wordpress.org/about/images/buttons/smbutton-grey.png" alt="" width="58" height="69" />I have been using Mambo/Joomla for quite some time and have realized that it&#039;s not ideal for blogging. I decided to go with a real blogging engine, like WordPress. It&#039;s really neat and easy to use and has a lot of plug-ins and features. I migrated all my joomla content with a <a href="http://azeemkhan.info/2008/joomla2wordpress-import-wizard-v3/" target="_blank">script</a> and it worked pretty well. Had to upload and fix all the images manually, and all the comments are missing, but what the heck, I am pretty satisfied.</p>
<p>My next move will be to create my own personal skin for WP, even though I like the one I am using. I just have to put this in the queue for all of my other projects and time consuming things.</p>
<p>Hope you like the new blog, at least I do. The old blog is still active and will be removed pretty soon. Redirects should work for most articles, so old links should be intact. Thanks to the <a href="http://wordpress.org/extend/plugins/redirection/" target="_blank">redirection plug-in</a> for WordPress <img src='http://hamang.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/09/18/moving-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
