<?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>Codelab Blog &#187; ASP.NET</title>
	<atom:link href="http://blog.codelab.co.nz/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Perform ASP.NET Postback using JQuery</title>
		<link>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/</link>
		<comments>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 23:47:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[ViewState]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=363</guid>
		<description><![CDATA[Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback. Firstly, add the following JQuery/Javascript code: &#60;script&#62; &#160;function autoSubmit() &#160;{ &#160;&#60;%= ClientScript.GetPostBackEventReference(btnSaveChanges, &#34;&#34;) %&#62;; &#160;} [...]]]></description>
			<content:encoded><![CDATA[<p>Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback.</p>
<p>Firstly, add the following JQuery/Javascript code:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;script&gt;<br />
<br />
&nbsp;function autoSubmit()<br />
&nbsp;{<br />
&nbsp;&lt;%= ClientScript.GetPostBackEventReference(btnSaveChanges, &quot;&quot;) %&gt;;<br />
&nbsp;}<br />
&nbsp; &nbsp; &nbsp;$(function () {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;#&lt;%= btnSaveChanges.ClientID %&gt;&quot;).click(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(this).attr(&quot;disabled&quot;, &quot;true&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;autoSubmit();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
&nbsp; &nbsp; &nbsp;});<br />
&lt;/script&gt;</div></div>
<p>You can inject the correct generated javascript code from using the function GetPostBackEventReference between the server tags.   Bind a click event to the ASP.NET server control which disables the button and call the autosubmit javascript function to perform a post back on the ASP.NET button control.   </p>
<p>References</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms153112.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms153112.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using UserControl.RenderControl()</title>
		<link>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/</link>
		<comments>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 22:08:15 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=341</guid>
		<description><![CDATA[Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose? Firstly, here is the code to render the html from a user control to a string builder object: &#160; &#160;Dim sb As New StringBuilder() &#160; &#160;Using sw As New StringWriter(sb) &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose?</p>
<p>Firstly, here is the code to render the html from a user control to a string builder object:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;Dim sb As New StringBuilder()<br />
&nbsp; &nbsp;Using sw As New StringWriter(sb)<br />
&nbsp; &nbsp; &nbsp; Using htmlTw As New HtmlTextWriter(sw)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim ucUserControl As UCUserControl = LoadControl(&quot;myUserControl.ascx&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .Visible = True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .Display() 'This is a custom method to do some processing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .RenderControl(htmlTw)<br />
&nbsp; &nbsp; &nbsp; End Using<br />
&nbsp; &nbsp;End Using</div></div>
<p>Secondly, make sure that you set <em><strong>enableEventValidation=&#8221;false&#8221;</strong></em> on the page you are generating the html from.   You will get an error if this is enabled.   You could extend this futher by adding a boolean variable to the page and only disabling Event Validation while rending the control.</p>
<p>Thirdly, override the <em><strong>VerifyRenderingInServerForm</strong></em> method and make it doing &#8220;nothing&#8221;.   If you do not do this, you will get an error saying that you have no form sever tag in your user control.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Public Overrides Sub VerifyRenderingInServerForm(control As System.Web.UI.Control)<br />
'Do nothing<br />
End Sub</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back to Basics &#8211; Deleting Cookies using ASP.NET</title>
		<link>http://blog.codelab.co.nz/2011/05/11/back-to-basics-deleting-cookies-using-asp-net/</link>
		<comments>http://blog.codelab.co.nz/2011/05/11/back-to-basics-deleting-cookies-using-asp-net/#comments</comments>
		<pubDate>Tue, 10 May 2011 23:21:58 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=331</guid>
		<description><![CDATA[You cannot instruct ASP.NET to physically remove cookies from the user&#8217;s computer so you have to tell the user&#8217;s browser to modify the cookie in order to trigger the browser to remove the cookie. See code example: HttpCookie aCookie; string cookieName; int limit = Request.Cookies.Count; for (int i=0; i { cookieName = Request.Cookies[i].Name; aCookie = [...]]]></description>
			<content:encoded><![CDATA[<p>You cannot instruct ASP.NET to physically remove cookies from the user&#8217;s computer so you have to tell the user&#8217;s browser to modify the cookie in order to trigger the browser to remove the cookie.</p>
<p>See code example:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">HttpCookie aCookie;<br />
string cookieName;<br />
int limit = Request.Cookies.Count;<br />
for (int i=0; i {<br />
cookieName = Request.Cookies[i].Name;<br />
aCookie = new HttpCookie(cookieName);<br />
aCookie.Expires = DateTime.Now.AddDays(-1);<br />
Response.Cookies.Add(aCookie);<br />
}</div></div>
<p>&nbsp;</p>
<p><strong><em>References:</em></strong></p>
<p><a title="Cookie Overview" href="http://msdn.microsoft.com/en-us/library/ms178194.aspx#Y5776" target="_blank">http://msdn.microsoft.com/en-us/library/ms178194.aspx#Y5776</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/05/11/back-to-basics-deleting-cookies-using-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect when a session has ended ASP.NET</title>
		<link>http://blog.codelab.co.nz/2010/06/30/detect-when-session-ended/</link>
		<comments>http://blog.codelab.co.nz/2010/06/30/detect-when-session-ended/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 03:32:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=259</guid>
		<description><![CDATA[A problem that I have had in the past is trying to find out when a session has expired within ASP.NET and how to deal with the expired session.   One solution is to add the following code into the Page_Init event.   You can add this event into a class that inherits the Page class so [...]]]></description>
			<content:encoded><![CDATA[<p>A problem that I have had in the past is trying to find out when a session has expired within ASP.NET and how to deal with the expired session.   One solution is to add the following code into the Page_Init event.   You can add this event into a class that inherits the Page class so that you can reuse on more than one page or all pages if needed.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">If Not Context.Session Is Nothing Then<br />
If Session.IsNewSession Then<br />
Dim szCookieHeader As String = Request.Headers(&quot;Cookie&quot;)<br />
If Not String.IsNullOrEmpty(szCookieHeader) And szCookieHeader.IndexOf(&quot;ASP.NET_SessionId&quot;) &amp;gt;= 0 Then<br />
Response.Redirect(&quot;/sessiontimeoutpage.aspx&quot;)<br />
End If<br />
End If<br />
End If</div></div>
<p>This code checks if a new session has been created and if the header has a ASP.NET Session id.   This makes sure that we are checking for a session that has just been created.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2010/06/30/detect-when-session-ended/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Could not load file or assembly &#8216;NameOfAssemblyGoesHere&#8217;</title>
		<link>http://blog.codelab.co.nz/2010/06/11/247/</link>
		<comments>http://blog.codelab.co.nz/2010/06/11/247/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 04:46:00 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=247</guid>
		<description><![CDATA[Encounted the following error: Could not load file or assembly &#8216;NameOfAssemblyGoesHere&#8217; or one of its dependencies. An attempt was made to load a program with an incorrect format. The problem happened when deploying a web application to a 64bit server where all the required DLL&#8217;s where marked as running only on a 32bit system.   You [...]]]></description>
			<content:encoded><![CDATA[<p>Encounted the following error:</p>
<blockquote><p>Could not load file or assembly &#8216;NameOfAssemblyGoesHere&#8217; or  one of its dependencies. An attempt was made to load a program with an  incorrect format.</p></blockquote>
<p>The problem happened when deploying a web application to a 64bit server where all the required DLL&#8217;s where marked as running only on a 32bit system.   You can change this by setting the target platform to AnyCPU which will solve this issue.   There is another workaround which is setting IIS compatability mode to 32bit, Open a command prompt and navigate to the  %systemdrive%\Inetpub\AdminScripts directory.  Type in the command cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 “true”.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2010/06/11/247/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change username in ASP.NET Membership Provider</title>
		<link>http://blog.codelab.co.nz/2010/05/31/change-username-in-asp-net-membership-provider/</link>
		<comments>http://blog.codelab.co.nz/2010/05/31/change-username-in-asp-net-membership-provider/#comments</comments>
		<pubDate>Sun, 30 May 2010 22:11:33 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=240</guid>
		<description><![CDATA[Found a great article here about the process of changing the username with the ASP.NET Membership Provider. Here is a summary of the process that I found best useful which is one of the comments: 1. Make sure New UserName is Unique 2. Update the aspnet_Users table directly 3. Execute to following code to change [...]]]></description>
			<content:encoded><![CDATA[<p>Found a great article <a href="http://omaralzabir.com/how_to_change_user_name_in_asp_net_2_0_membership_provider/">here </a>about the process of changing the username with the ASP.NET Membership Provider.</p>
<p>Here is a summary of the process that I found best useful which is one of the comments:</p>
<p>1. Make sure New UserName is Unique</p>
<p>2. Update the aspnet_Users table directly</p>
<p>3. Execute to following code to change the username/cookie/identity  without leaving the webpage…</p>
<p>&#8216; Obtains the name of the FormsAuthentication Cookie, uses that name  to request the Cookie and Decrypts the Cookies information into a  AuthTicket</p>
<p>Dim AuthTicket As FormsAuthenticationTicket =  FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName).Value)</p>
<p>&#8216; Instantiates a new user identity authenticated using forms  authentication based on the FormsAuthenticationTicket.</p>
<p>&#8216; The FormsAuthenticationTicket has been created using the exact same  parameters of the user with the Old Username except the Old Username  has been updated with the New Username.</p>
<p>Dim NewFormsIdentity As New FormsIdentity(New  FormsAuthenticationTicket(AuthTicket.Version, NewUsername,  AuthTicket.IssueDate, AuthTicket.Expiration, AuthTicket.IsPersistent,  AuthTicket.UserData))</p>
<p>&#8216; Parse out the AuthTicket&#8217;s UserData into a string array of Roles</p>
<p>Dim Roles As String() = AuthTicket.UserData.Split(“|”.ToCharArray)</p>
<p>&#8216; Creates a new user that has the NewFormsIdentity and belongs to the  array of Roles, if any, that was stored in the  FormsAuthenticationTicket</p>
<p>Dim NewGenericPrincipal As New  System.Security.Principal.GenericPrincipal(NewFormsIdentity, Roles)</p>
<p>&#8216; Sets the security information for the current HTTP request to the  new user.  The Username has now been changed (i.e.  HttpContext.Current.User.Identity.Name = NewUsername, prior to this step  is was the OldUsername)</p>
<p>HttpContext.Current.User = NewGenericPrincipal</p>
<p>&#8216; Removes the forms-authentication ticket from the browser</p>
<p>FormsAuthentication.SignOut()</p>
<p>&#8216; Cancels the current session</p>
<p>HttpContext.Current.Session.Abandon()</p>
<p>&#8216; Creates an authentication ticket for the supplied New Username and  adds it to the cookies collection of the response or the URL</p>
<p>FormsAuthentication.SetAuthCookie(HttpContext.Current.User.Identity.Name,  AuthTicket.IsPersistent)</p>
<p>4. Response.Redirect back to the same page if needed.</p>
<p><em><strong>References:</strong></em></p>
<p><a href="http://omaralzabir.com/how_to_change_user_name_in_asp_net_2_0_membership_provider/">http://omaralzabir.com/how_to_change_user_name_in_asp_net_2_0_membership_provider/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2010/05/31/change-username-in-asp-net-membership-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DateTime.ToString()</title>
		<link>http://blog.codelab.co.nz/2009/11/05/datetime-tostring/</link>
		<comments>http://blog.codelab.co.nz/2009/11/05/datetime-tostring/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 23:02:03 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=148</guid>
		<description><![CDATA[Here is a link that is useful as a reference for DateTime.ToString patterns References: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm]]></description>
			<content:encoded><![CDATA[<p>Here is a link that is useful as a reference for DateTime.ToString patterns</p>
<p>References:</p>
<p><a href="http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm">http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/11/05/datetime-tostring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the HttpWebRequest class</title>
		<link>http://blog.codelab.co.nz/2009/01/14/using-the-httpwebrequest-class/</link>
		<comments>http://blog.codelab.co.nz/2009/01/14/using-the-httpwebrequest-class/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 01:06:46 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=57</guid>
		<description><![CDATA[In this particular scenario I had to initiate a request from another website in code and track its response to be modified and rendered back to the user. I had a series of LinkButton html controls on the web form that consume one event. &#60;asp:LinkButton id=”link1” runat=”server” onClick=”genericEvent”&#62;&#60;/asp:LinkButton&#62; When the user clicks on a particular [...]]]></description>
			<content:encoded><![CDATA[<p>In this particular scenario I had to initiate a request from another website in code and track its response to be modified and rendered back to the user.</p>
<p>I had a series of LinkButton html controls on the web form that consume one event.</p>
<blockquote><p>&lt;asp:LinkButton id=”link1” runat=”server” onClick=”genericEvent”&gt;&lt;/asp:LinkButton&gt;</p></blockquote>
<p>When the user clicks on a particular button, ASP.Net invoked the genericEvent event</p>
<blockquote><p>Protected void genericEvent(object sender, EventArgs e)<br />
{<br />
LinkButton thisLink = (LinkButton)sender;<br />
}</p></blockquote>
<p>I have a Dictionary object that holds the ID of the LinkButton and a URL value</p>
<blockquote><p>Dictionary&lt;String,String&gt; Dict = new Dictionary&lt;String,String&gt;();<br />
Dict.Add(“ID”,http://www.google.co.nz);</p></blockquote>
<p>I created a helper method that initates the HttpWebRequest class to return a response based on the Dictionary ID and URL chosen from the user using the LinkButton.ID property.</p>
<blockquote><p>Private void GetResponse(String ID)<br />
{<br />
HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create(DicLinks[ID]);<br />
WebResponse newResponse = newRequest.GetResponse();<br />
newResponse.Close();<br />
}</p>
<p>Protected void genericEvent(object sender, EventArgs e)<br />
{<br />
LinkButton thisLink = (LinkButton)sender;<br />
GetResponse(thisLink.ID);<br />
}</p></blockquote>
<p>This proved very useful in the scenario of getting various types of information from different sources that can be manipulated and rendered into one view for the user.</p>
<p>References:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx">http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/01/14/using-the-httpwebrequest-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ASP.NET MVC on IIS6 or below</title>
		<link>http://blog.codelab.co.nz/2009/01/13/using-aspnet-mvc-on-iis6-or-below/</link>
		<comments>http://blog.codelab.co.nz/2009/01/13/using-aspnet-mvc-on-iis6-or-below/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 09:19:48 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=53</guid>
		<description><![CDATA[When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas.   But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment.   I found the easist way is to change [...]]]></description>
			<content:encoded><![CDATA[<p>When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas.   But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment.   I found the easist way is to change the URL routing table within the Global.asax file.</p>
<p>Origional file:</p>
<blockquote>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public class GlobalApplication : System.Web.HttpApplication</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);                routes.MapRoute(                     &quot;Default&quot;,// Route name                     &quot;{controller}/{action}/{id}&quot;,// URL with parameters                     new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; } &nbsp;                         // Parameter defaults                );</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;protected void Application_Start()</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;RegisterRoutes(RouteTable.Routes);</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
</blockquote>
<p>Change to the following:</p>
<blockquote>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public class GlobalApplication : System.Web.HttpApplication</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);                routes.MapRoute(                     &quot;Default&quot;,// Route name                     &quot;{controller}.aspx/{action}/{id}&quot;,// URL with parameters                     new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; } &nbsp;                         // Parameter defaults                );</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;protected void Application_Start()</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;{</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;RegisterRoutes(RouteTable.Routes);</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
<div class="codecolorer-container text default code_block" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;}</div></div>
</blockquote>
<p>Just add the .aspx extension so that it registers through the .NET Framework.</p>
<p>ALSO remember to do a Response.Redirect in the default.aspx page so that the first page will be your default URL routing page, otherwise you will receive a HttpException &#8220;The incoming request does not match any route.&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/01/13/using-aspnet-mvc-on-iis6-or-below/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>W3C Validation and ASP.NET ViewState</title>
		<link>http://blog.codelab.co.nz/2008/11/25/w3c-validation-and-aspnet-viewstate/</link>
		<comments>http://blog.codelab.co.nz/2008/11/25/w3c-validation-and-aspnet-viewstate/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 10:02:31 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ViewState]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=47</guid>
		<description><![CDATA[The problem I came across a very interesting point about validating XHTML pages using W3C XHTML Strict and ViewState.   By default ASP.NET ViewState adds a number of hidden fields to handle the postback of ASP.NET pages, control state and control event validation.  See example below. &#60;input type=&#8221;hidden&#8221; name=&#8221;__VIEWSTATE&#8221; id=&#8221;__VIEWSTATE&#8221; value=&#8221;"  /&#62; When validating web pages [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The problem</strong></p>
<p>I came across a very interesting point about validating XHTML pages using W3C XHTML Strict and ViewState.   By default ASP.NET ViewState adds a number of hidden fields to handle the postback of ASP.NET pages, control state and control event validation.  See example below.</p>
<blockquote><p>&lt;input type=&#8221;hidden&#8221; name=&#8221;__VIEWSTATE&#8221; id=&#8221;__VIEWSTATE&#8221; value=&#8221;"  /&gt;</p></blockquote>
<p>When validating web pages using the XHTML strict option, you will find that the above line is invalid:</p>
<blockquote><p>value of attribute &#8220;ID&#8221; invalid: &#8220;_&#8221; cannot start a name .<br />
…type=&#8221;hidden&#8221; name=&#8221;__VIEWSTATE&#8221; id=&#8221;__VIEWSTATE&#8221; value=&#8221;/wEPDwUJOTkzNjk4NjQ4</p></blockquote>
<p>This becomes a major issue when you have clients who expect their product to be compliant with todays web standards.</p>
<p><strong>The solution</strong></p>
<p><em>Step 1 -</em> I created a FilterModule that inherits the IHttpModule interface which will be the basis of renaming the __VIEWSTATE to VIEWSTATE.</p>
<blockquote><p>using System;<br />
using System.Web;</p>
<p>namespace Company.Utilities<br />
{<br />
public class IdFilterModule : IHttpModule<br />
{<br />
public void Dispose()<br />
{<br />
}<br />
public void Init(HttpApplication app)<br />
{<br />
app.ReleaseRequestState += new EventHandler(InstallResponseFilter);<br />
}<br />
private void InstallResponseFilter(object sender, EventArgs e)<br />
{<br />
HttpResponse response = HttpContext.Current.Response;</p>
<p>if (response.ContentType == &#8220;text/html&#8221;)<br />
{<br />
response.Filter = new IdFilter(response.Filter);<br />
}<br />
}<br />
}<br />
}</p></blockquote>
<p>The above code creates a event handler called InstallResponseFilter that gets fired when the ReleaseRequestState event is raised.   The ReleaseRequestState event saves all the current state data.</p>
<p><em>Step 2 -</em> I then create a class inheriting from the Stream class that takes the current state data and does a simple search and replace on the key ViewState identifiers and adjusts the output to be what we decide is valid XHTML.</p>
<blockquote><p>public class IdFilter : Stream<br />
{<br />
Stream responseStream;<br />
StringBuilder responseHtml;<br />
long position;</p>
<p>public IdFilter(Stream inputStream)<br />
{<br />
responseStream = inputStream;<br />
responseHtml = new StringBuilder();<br />
}</p>
<p>public override bool CanRead<br />
{<br />
get<br />
{<br />
return true;<br />
}<br />
}<br />
public override bool CanSeek<br />
{<br />
get<br />
{<br />
return true;<br />
}<br />
}<br />
public override bool CanWrite<br />
{<br />
get<br />
{<br />
return true;<br />
}<br />
}<br />
public override void Close()<br />
{<br />
responseStream.Close();<br />
}<br />
public override void Flush()<br />
{<br />
responseStream.Flush();<br />
}<br />
public override long Length<br />
{<br />
get<br />
{<br />
return 0;<br />
}<br />
}<br />
public override long Position<br />
{<br />
get<br />
{<br />
return position;<br />
}<br />
set<br />
{<br />
position = value;<br />
}<br />
}<br />
public override long Seek(long offset, SeekOrigin origin)<br />
{<br />
return responseStream.Seek(offset, origin);<br />
}<br />
public override void SetLength(long length)<br />
{<br />
responseStream.SetLength(length);<br />
}<br />
public override int Read(byte[] buffer, int offset, int count)<br />
{<br />
return responseStream.Read(buffer, offset, count);<br />
}<br />
public override void Write(byte[] buffer, int offset, int count)<br />
{<br />
string strBuffer = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);</p>
<p>Regex eof = new Regex(&#8220;&lt;/html&gt;&#8221;, RegexOptions.IgnoreCase);</p>
<p>if (!eof.IsMatch(strBuffer))<br />
{<br />
responseHtml.Append(strBuffer);<br />
}<br />
else<br />
{<br />
responseHtml.Append(strBuffer);</p>
<p>string finalHtml = responseHtml.ToString();</p>
<p>finalHtml = finalHtml.Replace(&#8220;id=\&#8221;__VIEWSTATE\&#8221;", &#8220;id=\&#8221;VIEWSTATE\&#8221;");<br />
finalHtml = finalHtml.Replace(&#8220;id=\&#8221;__EVENTARGUMENT\&#8221;", &#8220;id=\&#8221;\&#8221;EVENTARGUMENT&#8221;);<br />
finalHtml = finalHtml.Replace(&#8220;id=\&#8221;\&#8221;__EVENTTARGET&#8221;, &#8220;id=\&#8221;\&#8221;EVENTTARGET&#8221;);<br />
finalHtml = finalHtml.Replace(&#8220;  /&gt;&#8221;, &#8220;&gt;&#8221;);<br />
finalHtml = finalHtml.Replace(&#8221; /&gt;&#8221;, &#8220;&gt;&#8221;);<br />
finalHtml = finalHtml.Replace(&#8220;/&gt;&#8221;, &#8220;&gt;&#8221;);</p>
<p>byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(finalHtml);</p>
<p>responseStream.Write(data, 0, data.Length);<br />
}<br />
}<br />
}</p></blockquote>
<p>The new IdFilterModule gets registered is the web.config file under httpModules.</p>
<p>References:</p>
<p><a href="http://forum.umbraco.org/yaf_postst5965_W3C-Validation-ASPNET-ViewState-and-HTML-401.aspx">http://forum.umbraco.org/yaf_postst5965_W3C-Validation-ASPNET-ViewState-and-HTML-401.aspx</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.web.httpapplication.releaserequeststate.aspx">http://msdn.microsoft.com/en-us/library/system.web.httpapplication.releaserequeststate.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2008/11/25/w3c-validation-and-aspnet-viewstate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

