<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Mo Khan: My Blog! - ASP NET</title>
    <link>http://mokhan.ca/blog/</link>
    <description>Update your gray matter, because one day it may matter!</description>
    <language>en-us</language>
    <copyright>Mo Khan</copyright>
    <lastBuildDate>Fri, 15 Aug 2008 03:14:47 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>mo@mokhan.ca</managingEditor>
    <webMaster>mo@mokhan.ca</webMaster>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=c828d720-1724-442b-bc49-00efce6fd0ab</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,c828d720-1724-442b-bc49-00efce6fd0ab.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/ParsingThePayload_122CB/project_references_2.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="project_references" src="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/ParsingThePayload_122CB/project_references_thumb.png" width="174" align="right" border="0" />
          </a>So
this week we got to start working a brand spanking new MVC project. So far we're leveraging
Castle Windsor, NHibernate, Fluent Nhibernate, and kind of running Linq to NHibernate.
It's amazing how quickly you can get a project up and running in such a short amount
of time. (BTW, Fluent NHibernate rocks!) When you're building off the trunk of these
projects, it's almost like the contributors to all these great projects are extended
members of the team. Thank you all!
</p>
        <p>
Moving on... One of the things that are cool, but also slightly annoying, is how the
MVC framework parses out items from the http payload to populate any input arguments
on controller actions. 
</p>
        <p>
It's great how it just works, but it's a little annoying if it's under test and you
have to add more fields, or remove fields from a form, then you have to go update
the signature of the action then go update the test.... yada yada The changes just
ripple down...
</p>
        <p>
So one thing we tried out this week was to create a payload parser. What this guy
does is take a <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html">DTO</a> parse
out the values for each of the properties on the <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html">DTO</a> from
the current requests payload and fill it. This makes it easy to package up the form
parameters in a nicely packaged <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html">DTO</a> and
fire it off down to a service layer to do some work.
</p>
        <p>
So instead of declaring an action method on a controller that looks like this, where
the signature would have to change based on what fields are submitted on a form:
</p>
        <!-- code formatted by http://manoli.net/csharpformat/ -->
        <style type="text/css">





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>
        <pre class="csharpcode">ViewResult register_new_account(<span class="kwrd">string</span> user_name, <span class="kwrd">string</span> first_name, <span class="kwrd">string</span> last_name)</pre>
        <p>
We can write this...
</p>
        <!-- code formatted by http://manoli.net/csharpformat/ -->
        <style type="text/css">




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>
        <pre class="csharpcode">
          <span class="kwrd">public</span> ViewResult register_new_account()
{ var accountSubmissionDTO = parser.MapFromPayloadTo&lt;AccountSubmissionDTO&gt;();
var validationResult = task.Validate(accountSubmissionDTO); <span class="kwrd">if</span> (validationResult.IsValid)
{ task.Submit(accountSubmissionDTO); <span class="kwrd">return</span> View(<span class="str">"Success"</span>,
accountSubmissionDTO); } <span class="kwrd">return</span> View(<span class="str">"Index"</span>,
validationResult.BrokenRules); }</pre>
        <p>
This better allows us to adhere to the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">OCP</a>.
If we need to include additional fields on the form, we can add them to the form as
long as the control name is the same as the name of the property on the <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html">DTO</a> that
it will be bound to. The implementation of the payload parser is quite primitive for
now, but at the moment it's all that we needed.
</p>
        <p>
First up the specs... simple enough, for now!
</p>
        <p>
        </p>
        <!-- code formatted by http://manoli.net/csharpformat/ -->
        <style type="text/css">






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>
        <pre class="csharpcode">
          <span class="kwrd">public</span>
          <span class="kwrd">class</span> when_parsing_the_values_from_the_current_request_to_populate_a_dto
: context_spec&lt;IPayloadParser&gt; { [Test] <span class="kwrd">public</span><span class="kwrd">void</span> should_return_a_fully_populated_dto()
{ result.Name.should_be_equal_to(<span class="str">"adam"</span>); result.Age.should_be_equal_to(15);
result.Birthdate.should_be_equal_to(<span class="kwrd">new</span> DateTime(1982, 11,
25)); result.Id.should_be_equal_to(1); } <span class="kwrd">protected</span><span class="kwrd">override</span> IPayloadParser
UnderTheseConditions() { var current_request = Dependency&lt;IWebRequest&gt;(); var
payload = <span class="kwrd">new</span> NameValueCollection(); payload[<span class="str">"Name"</span>]
= <span class="str">"adam"</span>; payload[<span class="str">"Age"</span>]
= <span class="str">"15"</span>; payload[<span class="str">"Birthdate"</span>]
= <span class="kwrd">new</span> DateTime(1982, 11, 25).ToString(); payload[<span class="str">"Id"</span>]
= <span class="str">"1"</span>; current_request.setup_result_for(r =&gt;
r.Payload).Return(payload); <span class="kwrd">return</span><span class="kwrd">new</span> PayloadParser(current_request);
} <span class="kwrd">protected</span><span class="kwrd">override</span><span class="kwrd">void</span> BecauseOf()
{ result = sut.MapFromPayloadTo&lt;SomeDTO&gt;(); } <span class="kwrd">private</span> SomeDTO
result; } <span class="kwrd">public</span><span class="kwrd">class</span> when_parsing_values_from_the_request_that_is_missing_values_for_properties_on_the_dto
: context_spec&lt;IPayloadParser&gt; { <span class="kwrd">private</span> AccountSubmissionDTO
result; [Test] <span class="kwrd">public</span><span class="kwrd">void</span> it_should_apply_the_default_values_for_the_missing_properties()
{ result.LastName.should_be_null(); result.EmailAddress.should_be_null(); } <span class="kwrd">protected</span><span class="kwrd">override</span> IPayloadParser
UnderTheseConditions() { var current_request = Dependency&lt;IWebRequest&gt;(); var
payload = <span class="kwrd">new</span> NameValueCollection(); payload[<span class="str">"FirstName"</span>]
= <span class="str">"Joel"</span>; current_request.setup_result_for(x =&gt;
x.Payload).Return(payload); <span class="kwrd">return</span><span class="kwrd">new</span> PayloadParser(current_request);
} <span class="kwrd">protected</span><span class="kwrd">override</span><span class="kwrd">void</span> BecauseOf()
{ result = sut.MapFromPayloadTo&lt;AccountSubmissionDTO&gt;(); } } <span class="kwrd">public</span><span class="kwrd">class</span> SomeDTO
{ <span class="kwrd">public</span><span class="kwrd">long</span> Id { get; set; } <span class="kwrd">public</span><span class="kwrd">string</span> Name
{ get; set; } <span class="kwrd">public</span><span class="kwrd">int</span> Age {
get; set; } <span class="kwrd">public</span> DateTime Birthdate { get; set; } }</pre>
        <p>
The current implementation:
</p>
        <p>
        </p>
        <!-- code formatted by http://manoli.net/csharpformat/ -->
        <style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }</style>
        <pre class="csharpcode">
          <span class="kwrd">public</span>
          <span class="kwrd">interface</span> IPayloadParser
{ TypeToProduce MapFromPayloadTo&lt;TypeToProduce&gt;() <span class="kwrd">where</span> TypeToProduce
: <span class="kwrd">new</span>(); } <span class="kwrd">public</span><span class="kwrd">class</span> PayloadParser
: IPayloadParser { <span class="kwrd">private</span><span class="kwrd">readonly</span> IWebRequest
current_request; <span class="kwrd">public</span> PayloadParser(IWebRequest current_request)
{ <span class="kwrd">this</span>.current_request = current_request; } <span class="kwrd">public</span> TypeToProduce
MapFromPayloadTo&lt;TypeToProduce&gt;() <span class="kwrd">where</span> TypeToProduce
: <span class="kwrd">new</span>() { var dto = <span class="kwrd">new</span> TypeToProduce(); <span class="kwrd">foreach</span> (var
propertyInfo <span class="kwrd">in</span><span class="kwrd">typeof</span> (TypeToProduce).GetProperties())
{ var <span class="kwrd">value</span> = Convert.ChangeType(current_request.Payload[propertyInfo.Name],
propertyInfo.PropertyType); propertyInfo.SetValue(dto, <span class="kwrd">value</span>, <span class="kwrd">null</span>);
} <span class="kwrd">return</span> dto; } }</pre>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=c828d720-1724-442b-bc49-00efce6fd0ab" />
      </body>
      <title>Parsing The Payload</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,c828d720-1724-442b-bc49-00efce6fd0ab.aspx</guid>
      <link>http://mokhan.ca/blog/2008/08/15/Parsing+The+Payload.aspx</link>
      <pubDate>Fri, 15 Aug 2008 03:14:47 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/ParsingThePayload_122CB/project_references_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="project_references" src="http://mokhan.ca/blog/content/binary/WindowsLiveWriter/ParsingThePayload_122CB/project_references_thumb.png" width="174" align="right" border="0" /&gt;&lt;/a&gt;So
this week we got to start working a brand spanking new MVC project. So far we're leveraging
Castle Windsor, NHibernate, Fluent Nhibernate, and kind of running Linq to NHibernate.
It's amazing how quickly you can get a project up and running in such a short amount
of time. (BTW, Fluent NHibernate rocks!) When you're building off the trunk of these
projects, it's almost like the contributors to all these great projects are extended
members of the team. Thank you all!
&lt;/p&gt;
&lt;p&gt;
Moving on... One of the things that are cool, but also slightly annoying, is how the
MVC framework parses out items from the http payload to populate any input arguments
on controller actions. 
&lt;/p&gt;
&lt;p&gt;
It's great how it just works, but it's a little annoying if it's under test and you
have to add more fields, or remove fields from a form, then you have to go update
the signature of the action then go update the test.... yada yada The changes just
ripple down...
&lt;/p&gt;
&lt;p&gt;
So one thing we tried out this week was to create a payload parser. What this guy
does is take a &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;DTO&lt;/a&gt; parse
out the values for each of the properties on the &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;DTO&lt;/a&gt; from
the current requests payload and fill it. This makes it easy to package up the form
parameters in a nicely packaged &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;DTO&lt;/a&gt; and
fire it off down to a service layer to do some work.
&lt;/p&gt;
&lt;p&gt;
So instead of declaring an action method on a controller that looks like this, where
the signature would have to change based on what fields are submitted on a form:
&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;pre class="csharpcode"&gt;ViewResult register_new_account(&lt;span class="kwrd"&gt;string&lt;/span&gt; user_name, &lt;span class="kwrd"&gt;string&lt;/span&gt; first_name, &lt;span class="kwrd"&gt;string&lt;/span&gt; last_name)&lt;/pre&gt;
&lt;p&gt;
We can write this...
&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ViewResult register_new_account()
{ var accountSubmissionDTO = parser.MapFromPayloadTo&amp;lt;AccountSubmissionDTO&amp;gt;();
var validationResult = task.Validate(accountSubmissionDTO); &lt;span class="kwrd"&gt;if&lt;/span&gt; (validationResult.IsValid)
{ task.Submit(accountSubmissionDTO); &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Success&amp;quot;&lt;/span&gt;,
accountSubmissionDTO); } &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="str"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;,
validationResult.BrokenRules); }&lt;/pre&gt;
&lt;p&gt;
This better allows us to adhere to the &lt;a href="http://en.wikipedia.org/wiki/Open/closed_principle"&gt;OCP&lt;/a&gt;.
If we need to include additional fields on the form, we can add them to the form as
long as the control name is the same as the name of the property on the &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;DTO&lt;/a&gt; that
it will be bound to. The implementation of the payload parser is quite primitive for
now, but at the moment it's all that we needed.
&lt;/p&gt;
&lt;p&gt;
First up the specs... simple enough, for now!
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; when_parsing_the_values_from_the_current_request_to_populate_a_dto
: context_spec&amp;lt;IPayloadParser&amp;gt; { [Test] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; should_return_a_fully_populated_dto()
{ result.Name.should_be_equal_to(&lt;span class="str"&gt;&amp;quot;adam&amp;quot;&lt;/span&gt;); result.Age.should_be_equal_to(15);
result.Birthdate.should_be_equal_to(&lt;span class="kwrd"&gt;new&lt;/span&gt; DateTime(1982, 11,
25)); result.Id.should_be_equal_to(1); } &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IPayloadParser
UnderTheseConditions() { var current_request = Dependency&amp;lt;IWebRequest&amp;gt;(); var
payload = &lt;span class="kwrd"&gt;new&lt;/span&gt; NameValueCollection(); payload[&lt;span class="str"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;]
= &lt;span class="str"&gt;&amp;quot;adam&amp;quot;&lt;/span&gt;; payload[&lt;span class="str"&gt;&amp;quot;Age&amp;quot;&lt;/span&gt;]
= &lt;span class="str"&gt;&amp;quot;15&amp;quot;&lt;/span&gt;; payload[&lt;span class="str"&gt;&amp;quot;Birthdate&amp;quot;&lt;/span&gt;]
= &lt;span class="kwrd"&gt;new&lt;/span&gt; DateTime(1982, 11, 25).ToString(); payload[&lt;span class="str"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;]
= &lt;span class="str"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;; current_request.setup_result_for(r =&amp;gt;
r.Payload).Return(payload); &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; PayloadParser(current_request);
} &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BecauseOf()
{ result = sut.MapFromPayloadTo&amp;lt;SomeDTO&amp;gt;(); } &lt;span class="kwrd"&gt;private&lt;/span&gt; SomeDTO
result; } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; when_parsing_values_from_the_request_that_is_missing_values_for_properties_on_the_dto
: context_spec&amp;lt;IPayloadParser&amp;gt; { &lt;span class="kwrd"&gt;private&lt;/span&gt; AccountSubmissionDTO
result; [Test] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; it_should_apply_the_default_values_for_the_missing_properties()
{ result.LastName.should_be_null(); result.EmailAddress.should_be_null(); } &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IPayloadParser
UnderTheseConditions() { var current_request = Dependency&amp;lt;IWebRequest&amp;gt;(); var
payload = &lt;span class="kwrd"&gt;new&lt;/span&gt; NameValueCollection(); payload[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;]
= &lt;span class="str"&gt;&amp;quot;Joel&amp;quot;&lt;/span&gt;; current_request.setup_result_for(x =&amp;gt;
x.Payload).Return(payload); &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; PayloadParser(current_request);
} &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BecauseOf()
{ result = sut.MapFromPayloadTo&amp;lt;AccountSubmissionDTO&amp;gt;(); } } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SomeDTO
{ &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Id { get; set; } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name
{ get; set; } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Age {
get; set; } &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime Birthdate { get; set; } }&lt;/pre&gt;
&lt;p&gt;
The current implementation:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IPayloadParser
{ TypeToProduce MapFromPayloadTo&amp;lt;TypeToProduce&amp;gt;() &lt;span class="kwrd"&gt;where&lt;/span&gt; TypeToProduce
: &lt;span class="kwrd"&gt;new&lt;/span&gt;(); } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; PayloadParser
: IPayloadParser { &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IWebRequest
current_request; &lt;span class="kwrd"&gt;public&lt;/span&gt; PayloadParser(IWebRequest current_request)
{ &lt;span class="kwrd"&gt;this&lt;/span&gt;.current_request = current_request; } &lt;span class="kwrd"&gt;public&lt;/span&gt; TypeToProduce
MapFromPayloadTo&amp;lt;TypeToProduce&amp;gt;() &lt;span class="kwrd"&gt;where&lt;/span&gt; TypeToProduce
: &lt;span class="kwrd"&gt;new&lt;/span&gt;() { var dto = &lt;span class="kwrd"&gt;new&lt;/span&gt; TypeToProduce(); &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var
propertyInfo &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;typeof&lt;/span&gt; (TypeToProduce).GetProperties())
{ var &lt;span class="kwrd"&gt;value&lt;/span&gt; = Convert.ChangeType(current_request.Payload[propertyInfo.Name],
propertyInfo.PropertyType); propertyInfo.SetValue(dto, &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
} &lt;span class="kwrd"&gt;return&lt;/span&gt; dto; } }&lt;/pre&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=c828d720-1724-442b-bc49-00efce6fd0ab" /&gt;</description>
      <category>ASP NET</category>
      <category>CSharp</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=e8ad53bf-6b74-4f14-8096-cc48a11c94d6</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,e8ad53bf-6b74-4f14-8096-cc48a11c94d6.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So last week the guys and I at work started to spike ASP.NET MVC. We're starting up
a new project, and decided to take advantage of the Preview 2 version of the so far
released libraries. Our experiences so far have been.... hmmm... not as expected. 
</p>
        <p>
Here's a few things we've learned, hopefully they help someone else out. We're nant
junkies, so the first thing we did to get going was automate the compiling, testing,
running, deploying, and creation of the database with nant. We found that when running
our project against the aspnet_compiler.exe that it didn't recognize some of the new
C# 3.0 syntax. 
</p>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">select </span>
          <span style="color: red">name</span>
          <span style="color: blue">="protocolName"&gt; </span>
          <span style="background: #ffee62">&lt;%</span>
          <span style="color: blue">foreach</span>( <span style="color: blue">var </span>dto <span style="color: blue">in </span>ViewData
) {<span style="background: #ffee62">%&gt; </span><span style="color: blue">&lt;</span><span style="color: #a31515">option</span><span style="color: blue">&gt;</span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>dto.ProtocolName <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">option</span><span style="color: blue">&gt; </span><span style="background: #ffee62">&lt;%</span> } <span style="background: #ffee62">%&gt; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">select</span><span style="color: blue">&gt;</span></pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>The above code would raise an error
with the aspnet_compiler.exe. Now this is valid C# 3.0, but the pre compiler didn't
know what to do with the "var" keyword. Next, the precompiler didn't know
where to find the "Form()" method on the Html helper class because, it's
an extension method.
</p>
        <pre class="code">
          <span style="background: #ffee62">&lt;%</span>
          <span style="color: blue">using</span>(
Html.Form( <span style="color: #2b91af">Controllers</span>.<span style="color: #2b91af">Order</span>.Name, <span style="color: #a31515">"submit"</span>, <span style="color: #2b91af">FormMethod</span>.Post
) ) {<span style="background: #ffee62">%&gt; </span></pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>
        </p>
        <p>
 
</p>
        <p>
It's kind of an interesting idea that so many methods on the "HtmlHelper"
class are extension methods. The solution to getting the aspnet_precompiler to recognize
the C#3.0 syntax was to dump this block of xml in the web.config.
</p>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">system.codedom</span>
          <span style="color: blue">&gt;
&lt;</span>
          <span style="color: #a31515">compilers</span>
          <span style="color: blue">&gt;
&lt;</span>
          <span style="color: #a31515">compiler </span>
          <span style="color: red">language</span>
          <span style="color: blue">=</span>"<span style="color: blue">c#;cs;csharp</span>" <span style="color: red">extension</span><span style="color: blue">=</span>"<span style="color: blue">.cs</span>" <span style="color: red">warningLevel</span><span style="color: blue">=</span>"<span style="color: blue">4</span>" <span style="color: red">type</span><span style="color: blue">=</span>"<span style="color: blue">Microsoft.CSharp.CSharpCodeProvider,
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</span>"<span style="color: blue">&gt;
&lt;</span><span style="color: #a31515">providerOption </span><span style="color: red">name</span><span style="color: blue">=</span>"<span style="color: blue">CompilerVersion</span>" <span style="color: red">value</span><span style="color: blue">=</span>"<span style="color: blue">v3.5</span>"<span style="color: blue">/&gt;
&lt;</span><span style="color: #a31515">providerOption </span><span style="color: red">name</span><span style="color: blue">=</span>"<span style="color: blue">WarnAsError</span>" <span style="color: red">value</span><span style="color: blue">=</span>"<span style="color: blue">false</span>"<span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">compiler</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">compilers</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">system.codedom</span><span style="color: blue">&gt;</span></pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>Next up... testing controllers. I
think the guys and I were a little surprised at just how awkward it was to test a
controller. I thought, a lot of time was spent making the controllers more testable.
Our first pain point was the fact that "RenderView()" is a protected method
on the Controller base class. Here's what I'm talking about...
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">HomeController </span>: <span style="color: #2b91af">Controller </span>{ <span style="color: blue">public
void </span>Index( ) { RenderView( <span style="color: #a31515">"Index" </span>);
} <span style="color: blue">public void </span>About( ) { RenderView( <span style="color: #a31515">"About" </span>);
} }</pre>
        <p>
 
</p>
        <p>
So let's think... how can we test that when the Index action is invoked it calls "RenderView"
with an argument value "Index"... So some people have suggested creating
a Test Double. I say... booo... I use mock object frameworks so that I don't need
to groom a garden of hand rolled test stubs. Here's what we came up with... first
cut remember!
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">OrderController </span>: <span style="color: #2b91af">BaseController</span>, <span style="color: #2b91af">IOrderController </span>{ <span style="color: blue">private
readonly </span><span style="color: #2b91af">IOrderIndexCommand </span>indexCommand; <span style="color: blue">private
readonly </span><span style="color: #2b91af">ISubmitOrderCommand </span>submitCommand; <span style="color: blue">public </span>OrderController( <span style="color: #2b91af">IOrderIndexCommand </span>indexCommand, <span style="color: #2b91af">ISubmitOrderCommand </span>submitCommand
) { <span style="color: blue">this</span>.indexCommand = indexCommand; <span style="color: blue">this</span>.submitCommand
= submitCommand; } <span style="color: blue">public void </span>Index( ) { indexCommand.InitializeWith( <span style="color: blue">this </span>);
indexCommand.Execute( ); } <span style="color: blue">public void </span>Submit( )
{ submitCommand.InitializeWith( <span style="color: blue">this </span>); submitCommand.Execute(
); } }</pre>
        <p>
 
</p>
        <p>
Ok... so it's slightly more testable. Each action on the controller executes a command,
after first being initialized with ... The other thing to notice is that the OrderController
inherits from BaseController. BaseController is actually an adapter that implements
an IViewRenderer interface.
</p>
        <pre class="code">
          <span style="color: blue">public abstract class </span>
          <span style="color: #2b91af">BaseController </span>: <span style="color: #2b91af">Controller</span>, <span style="color: #2b91af">IViewRenderer </span>{ <span style="color: blue">public
void </span>Render&lt; TypeToBindToView &gt;( <span style="color: #2b91af">IView </span>view,
TypeToBindToView viewData ) { RenderView( view.Name( ), viewData ); } }</pre>
        <p>
 
</p>
        <p>
The OrderIndexCommand is initialized with an IViewRenderer. 
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">OrderIndexCommand </span>: <span style="color: #2b91af">IOrderIndexCommand </span>{ <span style="color: blue">private </span><span style="color: #2b91af">IViewRenderer </span>viewEngine; <span style="color: blue">private
readonly </span><span style="color: #2b91af">IOrderTasks </span>task; <span style="color: blue">public </span>OrderIndexCommand( <span style="color: #2b91af">IOrderTasks </span>task
) { <span style="color: blue">this</span>.task = task; } <span style="color: blue">public
void </span>InitializeWith( <span style="color: #2b91af">IViewRenderer </span>engineToRenderViews
) { viewEngine = engineToRenderViews; } <span style="color: blue">public void </span>Execute(
) { viewEngine.Render( <span style="color: #2b91af">ControllerViews</span>.<span style="color: #2b91af">Order</span>.Index,
task.RetrieveAllProtocols( ) ); } }</pre>
        <p>
          <a href="http://11011.net/software/vspaste"> </a>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=e8ad53bf-6b74-4f14-8096-cc48a11c94d6" />
      </body>
      <title>Spikin' MVC</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,e8ad53bf-6b74-4f14-8096-cc48a11c94d6.aspx</guid>
      <link>http://mokhan.ca/blog/2008/05/17/Spikin+MVC.aspx</link>
      <pubDate>Sat, 17 May 2008 21:35:30 GMT</pubDate>
      <description>&lt;p&gt;
So last week the guys and I at work started to spike ASP.NET MVC. We're starting up
a new project, and decided to take advantage of the Preview 2 version of the so far
released libraries. Our experiences so far have been.... hmmm... not as expected. 
&lt;/p&gt;
&lt;p&gt;
Here's a few things we've learned, hopefully they help someone else out. We're nant
junkies, so the first thing we did to get going was automate the compiling, testing,
running, deploying, and creation of the database with nant. We found that when running
our project against the aspnet_compiler.exe that it didn't recognize some of the new
C# 3.0 syntax. 
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;select &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;protocolName&amp;quot;&amp;gt; &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;foreach&lt;/span&gt;( &lt;span style="color: blue"&gt;var &lt;/span&gt;dto &lt;span style="color: blue"&gt;in &lt;/span&gt;ViewData
) {&lt;span style="background: #ffee62"&gt;%&amp;gt; &lt;/span&gt; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;option&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;= &lt;/span&gt;dto.ProtocolName &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;option&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; } &lt;span style="background: #ffee62"&gt;%&amp;gt; &lt;/span&gt; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;select&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;The above code would raise an error
with the aspnet_compiler.exe. Now this is valid C# 3.0, but the pre compiler didn't
know what to do with the &amp;quot;var&amp;quot; keyword. Next, the precompiler didn't know
where to find the &amp;quot;Form()&amp;quot; method on the Html helper class because, it's
an extension method.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;using&lt;/span&gt;(
Html.Form( &lt;span style="color: #2b91af"&gt;Controllers&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Order&lt;/span&gt;.Name, &lt;span style="color: #a31515"&gt;&amp;quot;submit&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;FormMethod&lt;/span&gt;.Post
) ) {&lt;span style="background: #ffee62"&gt;%&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
It's kind of an interesting idea that so many methods on the &amp;quot;HtmlHelper&amp;quot;
class are extension methods. The solution to getting the aspnet_precompiler to recognize
the C#3.0 syntax was to dump this block of xml in the web.config.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.codedom&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;compilers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;compiler &lt;/span&gt;&lt;span style="color: red"&gt;language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;c#;cs;csharp&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;extension&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;.cs&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;warningLevel&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;4&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Microsoft.CSharp.CSharpCodeProvider,
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;providerOption &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;CompilerVersion&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;v3.5&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;providerOption &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;WarnAsError&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;false&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;compiler&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;compilers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.codedom&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Next up... testing controllers. I
think the guys and I were a little surprised at just how awkward it was to test a
controller. I thought, a lot of time was spent making the controllers more testable.
Our first pain point was the fact that &amp;quot;RenderView()&amp;quot; is a protected method
on the Controller base class. Here's what I'm talking about...
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HomeController &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Controller &lt;/span&gt;{ &lt;span style="color: blue"&gt;public
void &lt;/span&gt;Index( ) { RenderView( &lt;span style="color: #a31515"&gt;&amp;quot;Index&amp;quot; &lt;/span&gt;);
} &lt;span style="color: blue"&gt;public void &lt;/span&gt;About( ) { RenderView( &lt;span style="color: #a31515"&gt;&amp;quot;About&amp;quot; &lt;/span&gt;);
} }&lt;/pre&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
So let's think... how can we test that when the Index action is invoked it calls &amp;quot;RenderView&amp;quot;
with an argument value &amp;quot;Index&amp;quot;... So some people have suggested creating
a Test Double. I say... booo... I use mock object frameworks so that I don't need
to groom a garden of hand rolled test stubs. Here's what we came up with... first
cut remember!
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderController &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;BaseController&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;IOrderController &lt;/span&gt;{ &lt;span style="color: blue"&gt;private
readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IOrderIndexCommand &lt;/span&gt;indexCommand; &lt;span style="color: blue"&gt;private
readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ISubmitOrderCommand &lt;/span&gt;submitCommand; &lt;span style="color: blue"&gt;public &lt;/span&gt;OrderController( &lt;span style="color: #2b91af"&gt;IOrderIndexCommand &lt;/span&gt;indexCommand, &lt;span style="color: #2b91af"&gt;ISubmitOrderCommand &lt;/span&gt;submitCommand
) { &lt;span style="color: blue"&gt;this&lt;/span&gt;.indexCommand = indexCommand; &lt;span style="color: blue"&gt;this&lt;/span&gt;.submitCommand
= submitCommand; } &lt;span style="color: blue"&gt;public void &lt;/span&gt;Index( ) { indexCommand.InitializeWith( &lt;span style="color: blue"&gt;this &lt;/span&gt;);
indexCommand.Execute( ); } &lt;span style="color: blue"&gt;public void &lt;/span&gt;Submit( )
{ submitCommand.InitializeWith( &lt;span style="color: blue"&gt;this &lt;/span&gt;); submitCommand.Execute(
); } }&lt;/pre&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Ok... so it's slightly more testable. Each action on the controller executes a command,
after first being initialized with ... The other thing to notice is that the OrderController
inherits from BaseController. BaseController is actually an adapter that implements
an IViewRenderer interface.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public abstract class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BaseController &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Controller&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;IViewRenderer &lt;/span&gt;{ &lt;span style="color: blue"&gt;public
void &lt;/span&gt;Render&amp;lt; TypeToBindToView &amp;gt;( &lt;span style="color: #2b91af"&gt;IView &lt;/span&gt;view,
TypeToBindToView viewData ) { RenderView( view.Name( ), viewData ); } }&lt;/pre&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
The OrderIndexCommand is initialized with an IViewRenderer. 
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderIndexCommand &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;IOrderIndexCommand &lt;/span&gt;{ &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IViewRenderer &lt;/span&gt;viewEngine; &lt;span style="color: blue"&gt;private
readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IOrderTasks &lt;/span&gt;task; &lt;span style="color: blue"&gt;public &lt;/span&gt;OrderIndexCommand( &lt;span style="color: #2b91af"&gt;IOrderTasks &lt;/span&gt;task
) { &lt;span style="color: blue"&gt;this&lt;/span&gt;.task = task; } &lt;span style="color: blue"&gt;public
void &lt;/span&gt;InitializeWith( &lt;span style="color: #2b91af"&gt;IViewRenderer &lt;/span&gt;engineToRenderViews
) { viewEngine = engineToRenderViews; } &lt;span style="color: blue"&gt;public void &lt;/span&gt;Execute(
) { viewEngine.Render( &lt;span style="color: #2b91af"&gt;ControllerViews&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Order&lt;/span&gt;.Index,
task.RetrieveAllProtocols( ) ); } }&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&amp;#160;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=e8ad53bf-6b74-4f14-8096-cc48a11c94d6" /&gt;</description>
      <category>ASP NET</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=c2a60fa5-162f-42c0-99a8-8542629fff07</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,c2a60fa5-162f-42c0-99a8-8542629fff07.aspx</pingback:target>
      <dc:creator>Mr mO!</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This month I've been going pretty hard core about learning ASP.NET and I was having
a lot of difficulty with playing with the ASPX view engine. I'm already fairly familiar
with HTML and CSS, but now I have to learn these new ASP.NET controls? Why can't I
just stick to the HTML and CSS I know and enjoy working with?
</p>
        <p>
Well it turns out I can... I don't need to learn about the complex data binding of
a GridView or how an ASP:TextBox converts to a plain ol' input tag wrapped in span
tags. I've been heavily studying the work from the project we worked on during the <a href="http://mokhan.ca/blog/2007/11/13/Photos+From+The+Nothin+But+NET+Boot+Camp.aspx">Nothin'
But .NET boot camp</a> and reading up on the <a href="http://support.microsoft.com/kb/307860#1a">MSDN
documentation on inlining aspx</a>.
</p>
        <p>
I like it... C'mon doesn't this....
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">&lt;</span>
          <span style="color: rgb(163,21,21)">h1</span>
          <span style="color: rgb(0,0,255)">&gt;</span>Available
Slips<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">h1</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">table</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">thead</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span>Location
Name<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span>Dock
Name<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span>Slip
Width<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span>Slip
Length<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">thead</span><span style="color: rgb(0,0,255)">&gt;</span><span style="background: rgb(255,238,98)">&lt;%</span><span style="color: rgb(0,0,255)">foreach</span> ( <span style="color: rgb(43,145,175)">SlipDisplayDTO</span> item <span style="color: rgb(0,0,255)">in</span><span style="color: rgb(43,145,175)">ViewLuggage</span>.ClaimFor(<span style="color: rgb(43,145,175)">ViewLuggageTickets</span>.AvailableSlips)
) {<span style="background: rgb(255,238,98)">%&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>=</span> item.LocationName <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">a</span><span style="color: rgb(255,0,0)">href</span><span style="color: rgb(0,0,255)">='</span><span style="background: rgb(255,238,98)">&lt;%</span>=
WebViews.DockView.Name( ) <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>?</span><span style="background: rgb(255,238,98)">&lt;%</span>=
PayloadKeys.DockId <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>=</span><span style="background: rgb(255,238,98)">&lt;%</span>=
item.DockId <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>'&gt; </span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>=</span> item.DockName <span style="background: rgb(255,238,98)">%&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">a</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>=</span> item.Width <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>=</span> item.Length <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt; </span><span style="background: rgb(255,238,98)">&lt;%</span> } <span style="background: rgb(255,238,98)">%&gt;</span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">table</span><span style="color: rgb(0,0,255)">&gt;</span></pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
Seem a lot more readable then this...
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">&lt;</span>
          <span style="color: rgb(163,21,21)">asp</span>
          <span style="color: rgb(0,0,255)">:</span>
          <span style="color: rgb(163,21,21)">Repeater</span>
          <span style="color: rgb(255,0,0)">ID</span>
          <span style="color: rgb(0,0,255)">="uxSlipsRepeater"</span>
          <span style="color: rgb(255,0,0)">runat</span>
          <span style="color: rgb(0,0,255)">="server"&gt;
&lt;</span>
          <span style="color: rgb(163,21,21)">HeaderTemplate</span>
          <span style="color: rgb(0,0,255)">&gt;
&lt;</span>
          <span style="color: rgb(163,21,21)">table</span>
          <span style="color: rgb(0,0,255)">&gt;
&lt;</span>
          <span style="color: rgb(163,21,21)">thead</span>
          <span style="color: rgb(0,0,255)">&gt; </span>
          <span style="color: rgb(0,0,255)">&lt;</span>
          <span style="color: rgb(163,21,21)">tr</span>
          <span style="color: rgb(0,0,255)">&gt; </span>
          <span style="color: rgb(0,0,255)">&lt;</span>
          <span style="color: rgb(163,21,21)">td</span>
          <span style="color: rgb(0,0,255)">&gt;</span>Dock
Name<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span>Slip
Width<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span>Slip
Length<span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt;
&lt;/</span><span style="color: rgb(163,21,21)">thead</span><span style="color: rgb(0,0,255)">&gt;
&lt;/</span><span style="color: rgb(163,21,21)">HeaderTemplate</span><span style="color: rgb(0,0,255)">&gt;
&lt;</span><span style="color: rgb(163,21,21)">ItemTemplate</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;
&lt;</span><span style="color: rgb(163,21,21)">a</span><span style="color: rgb(255,0,0)">href</span><span style="color: rgb(0,0,255)">='DockView.aspx?</span><span style="background: rgb(255,238,98)">&lt;%</span>=
PayLoadKeys.DockId <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>=</span><span style="background: rgb(255,238,98)">&lt;%</span>#
((SlipDisplayDTO)Container.DataItem).DockId <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>'&gt; </span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>#</span><span style="color: rgb(43,145,175)">Transform</span>.From(Container.DataItem).AndConvertItToAn&lt;<span style="color: rgb(43,145,175)">SlipDisplayDTO</span>&gt;().DockName <span style="background: rgb(255,238,98)">%&gt; <span style="color: rgb(0,0,255)"></span>&lt;/</span><span style="color: rgb(163,21,21)">a</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>#</span><span style="color: rgb(43,145,175)">Transform</span>.From(Container.DataItem).AndConvertItToAn&lt;<span style="color: rgb(43,145,175)">SlipDisplayDTO</span>&gt;().Width <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="background: rgb(255,238,98)">&lt;%<span style="color: rgb(0,0,255)"></span>#</span><span style="color: rgb(43,145,175)">Transform</span>.From(Container.DataItem).AndConvertItToAn&lt;<span style="color: rgb(43,145,175)">SlipDisplayDTO</span>&gt;().Length <span style="background: rgb(255,238,98)">%&gt;<span style="color: rgb(0,0,255)"></span>&lt;/</span><span style="color: rgb(163,21,21)">td</span><span style="color: rgb(0,0,255)">&gt; </span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(163,21,21)">tr</span><span style="color: rgb(0,0,255)">&gt;
&lt;/</span><span style="color: rgb(163,21,21)">ItemTemplate</span><span style="color: rgb(0,0,255)">&gt;
&lt;</span><span style="color: rgb(163,21,21)">FooterTemplate</span><span style="color: rgb(0,0,255)">&gt;
&lt;/</span><span style="color: rgb(163,21,21)">table</span><span style="color: rgb(0,0,255)">&gt;
&lt;/</span><span style="color: rgb(163,21,21)">FooterTemplate</span><span style="color: rgb(0,0,255)">&gt;
&lt;/</span><span style="color: rgb(163,21,21)">asp</span><span style="color: rgb(0,0,255)">:</span><span style="color: rgb(163,21,21)">Repeater</span><span style="color: rgb(0,0,255)">&gt;</span></pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>The extra asp namespaces appended
to all the controls just seem like noise. The explicit casting from Container.DataItem
to the type actually contained seems like extra work. I suppose you could write all
this out in an item data bound event handler. But it just looks like noise, noise
noise... Then when you actually look at the HTML that's spit out it loaded with more
noise...
</p>
        <p>
For example:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">&lt;</span>
          <span style="color: rgb(163,21,21)">input</span>
          <span style="color: rgb(255,0,0)">name</span>
          <span style="color: rgb(0,0,255)">="ctl00$ContentPlaceHolder2$uxUserNameTextBox"</span>
          <span style="color: rgb(255,0,0)">type</span>
          <span style="color: rgb(0,0,255)">="text"</span>
          <span style="color: rgb(255,0,0)">id</span>
          <span style="color: rgb(0,0,255)">="ctl00_ContentPlaceHolder2_uxUserNameTextBox"</span>
          <span style="color: rgb(0,0,255)">/&gt;</span>
        </pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <font face="Courier New">
        </font>
        <p>
Versus:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">&lt;</span>
          <span style="color: rgb(163,21,21)">input</span>
          <span style="color: rgb(255,0,0)">name</span>
          <span style="color: rgb(0,0,255)">="uxUserNameTextBox"</span>
          <span style="color: rgb(255,0,0)">type</span>
          <span style="color: rgb(0,0,255)">="text"</span>
          <span style="color: rgb(0,0,255)">/&gt;</span>
        </pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a>Well all of this can be avoided. But
you're going to have to get just a little bit deeper, and here's how. Everything you
need to know is in <a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.aspx">HttpContext</a>.
Yup! 
</p>
        <p>
Instead of dropping an ASP:TextBox on the page try an <a href="http://www.w3schools.com/tags/tag_input.asp">input
element</a> and parse out the value in the input element from the <a href="http://msdn2.microsoft.com/en-us/library/system.web.httprequest.params.aspx">HttpContext.Current.Request.Params</a>.
This is a NameValueCollection that has all the Http Headers that were sent along the
trip to the server AKA <a href="http://www.w3.org/TR/2003/WD-di-gloss-20030825/#def-http-payload-entity">The
Payload</a>.
</p>
        <p>
For my current school assignment I'm currently flushing out the concept of an HttpGateway,
where all traffic comes in and all traffic goes out. Currently this is just wrapping
and HttpContext but with an interface that works better for me as a client of it.
I don't need to see everything available in the HttpContext (which is a lot!). 
</p>
        <p>
Next up, take advantage of the <a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.items.aspx">HttpContext.Items</a> collection.
This is a collection of objects which you can load up with extra information to pass
on down the pipeline. Consider the concept of view luggage, where luggage is issued
a ticket when you drop it off. You can then claim that luggage using the same luggage
ticket.
</p>
        <p>
What does this mean, you can have your presenters, controllers, commands (whatever)
drop off luggage to be carried to the view. You can then have your views claim that
luggage with the luggage ticket. (Take a look back at the first bit of HTML markup
in this post.)
</p>
        <p>
The <a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.items.aspx">HttpContext.Items</a> collection
is a dictionary for objects. Using strongly typed luggage tickets you can make that
the key, and the actual luggage the value to store in the items collection. The HttpContext
then becomes the airplane, carrier or transporter that hauls your luggage from your
presenter, controller, command (whatever) to the view.
</p>
        <p>
For the quick and dirty here's the code that describes what I'm talking about:
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">ViewLuggageTransporter</span>&lt;
Luggage &gt; : <span style="color: rgb(43,145,175)">IViewLuggageTransporter</span>&lt;
Luggage &gt; { <span style="color: rgb(0,0,255)">public</span> ViewLuggageTransporter( <span style="color: rgb(43,145,175)">IViewLuggageTicket</span>&lt;
Luggage &gt; key ) : <span style="color: rgb(0,0,255)">this</span>( key, <span style="color: rgb(43,145,175)">HttpContext</span>.Current.Items
) {} <span style="color: rgb(0,0,255)">private</span> ViewLuggageTransporter( <span style="color: rgb(43,145,175)">IViewLuggageTicket</span>&lt;
Luggage &gt; key, <span style="color: rgb(43,145,175)">IDictionary</span> items )
{ _ticket = key; _items = items; } <span style="color: rgb(0,0,255)">public</span> Luggage
Value() { <span style="color: rgb(0,0,255)">foreach</span> ( <span style="color: rgb(43,145,175)">DictionaryEntry</span> entry <span style="color: rgb(0,0,255)">in</span> _items
) { <span style="color: rgb(0,0,255)">if</span> ( entry.Key.Equals( _ticket ) ) { <span style="color: rgb(0,0,255)">return</span> (
Luggage )entry.Value; } } <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">default</span>(
Luggage ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> Add(
Luggage value ) { _items.Add( _ticket, value ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IViewLuggageTicket</span>&lt;
Luggage &gt; _ticket; <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">readonly</span><span style="color: rgb(43,145,175)">IDictionary</span> _items;
} <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">ViewLuggage</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(43,145,175)">IViewLuggageTransporter</span>&lt;
T &gt; TransporterFor&lt; T &gt;( <span style="color: rgb(43,145,175)">IViewLuggageTicket</span>&lt;
T &gt; ticket ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">ViewLuggageTransporter</span>&lt;
T &gt;( ticket ); } <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">static</span> T
ClaimFor&lt; T &gt;( <span style="color: rgb(43,145,175)">IViewLuggageTicket</span>&lt;
T &gt; ticket ) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">ViewLuggageTransporter</span>&lt;
T &gt;( ticket ).Value( ); } }</pre>
        <p>
To parse out the value submitted in a request you can create mappers to parse out
the values for each control. In the code below each of the string literals prefixed
with a "ux" represents the name of the html control that was on the page.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">class</span>
          <span style="color: rgb(43,145,175)">UpdateRegistrationPresentationMapper</span> : <span style="color: rgb(43,145,175)">IUpdateRegistrationPresentationMapper</span> { <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">UpdateCustomerRegistrationDTO</span> MapFrom( <span style="color: rgb(43,145,175)">IHttpRequest</span> input
) { <span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">UpdateCustomerRegistrationDTO</span>(
input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.CustomerId
), input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.For( <span style="color: rgb(163,21,21)">"uxUserNameTextBox"</span> )
), input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.For( <span style="color: rgb(163,21,21)">"uxPasswordTextBox"</span> )
), input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.For( <span style="color: rgb(163,21,21)">"uxFirstNameTextBox"</span> )
), input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.For( <span style="color: rgb(163,21,21)">"uxLastNameTextBox"</span> )
), input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.For( <span style="color: rgb(163,21,21)">"uxPhoneNumberTextBox"</span> )
), input.ParsePayloadFor( <span style="color: rgb(43,145,175)">PayloadKeys</span>.For( <span style="color: rgb(163,21,21)">"uxCityTextBox"</span> )
) ); } }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
For an even sweeter example check out the source code for the <a href="http://www.jpboodhoo.com/blog/codegooglecompjpboodhoo.aspx">NothinButDotNetStore</a>. 
</p>
        <p>
Next up, figuring out a cleaner way to implement authorization and authentication
without having to rely on the FormsAuthentication class. So far my spiking of Forms
Auth looks something like the code below... <strong>*Please do not use the code below.
I was just trying to understand how forms auth works and this is not a great example
of how you should use it.</strong></p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">public</span>
          <span style="color: rgb(0,0,255)">void</span> AuthenticateHttpRequest(
) { <span style="color: rgb(43,145,175)">HttpCookie</span> cookie = GetCookieFrom( <span style="color: rgb(43,145,175)">HttpContext</span>.Current
); <span style="color: rgb(0,0,255)">if</span> ( <span style="color: rgb(0,0,255)">null</span> !=
cookie ) { BindPrincipalToThreadUsing( _mapper.MapFrom( <span style="color: rgb(43,145,175)">FormsAuthentication</span>.Decrypt(
cookie.Value ) ) ); } } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(43,145,175)">HttpCookie</span> GetCookieFrom( <span style="color: rgb(43,145,175)">HttpContext</span> context
) { <span style="color: rgb(0,0,255)">return</span> context.Request.Cookies[ <span style="color: rgb(43,145,175)">FormsAuthentication</span>.FormsCookieName
]; } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">void</span> BindPrincipalToThreadUsing( <span style="color: rgb(43,145,175)">CustomerCookieCredentials</span> credentials
) { <span style="color: rgb(43,145,175)">IIdentity</span> identity = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">CustomerIdentity</span>(
credentials.Username, credentials.Username ); <span style="color: rgb(43,145,175)">HttpContext</span>.Current.User
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">GenericPrincipal</span>(
identity, <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,255)">string</span>[]
{<span style="color: rgb(163,21,21)">"customer"</span>} ); } <span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,255)">void</span> AddAuthenticationTicket(
) { <span style="color: rgb(43,145,175)">FormsAuthenticationTicket</span> ticket = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">FormsAuthenticationTicket</span>(
1, <span style="color: rgb(163,21,21)">"mo"</span>, <span style="color: rgb(43,145,175)">DateTime</span>.Now, <span style="color: rgb(43,145,175)">DateTime</span>.Now.AddMinutes(
20 ), <span style="color: rgb(0,0,255)">false</span>, <span style="color: rgb(163,21,21)">"2"</span> ); <span style="color: rgb(0,0,255)">string</span> cookieValue
= <span style="color: rgb(43,145,175)">FormsAuthentication</span>.Encrypt( ticket
); <span style="color: rgb(43,145,175)">HttpContext</span> current = <span style="color: rgb(43,145,175)">HttpContext</span>.Current;
current.Response.Cookies.Add( <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">HttpCookie</span>( <span style="color: rgb(43,145,175)">FormsAuthentication</span>.FormsCookieName,
cookieValue ) ); <span style="color: rgb(43,145,175)">IIdentity</span> identity = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">CustomerIdentity</span>( <span style="color: rgb(163,21,21)">"mo"</span>, <span style="color: rgb(163,21,21)">"2"</span> );
current.User = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">GenericPrincipal</span>(
identity, <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,255)">string</span>[]
{<span style="color: rgb(163,21,21)">"customer"</span>} ); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=c2a60fa5-162f-42c0-99a8-8542629fff07" />
      </body>
      <title>What's Wrong With Inline ASPX</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,c2a60fa5-162f-42c0-99a8-8542629fff07.aspx</guid>
      <link>http://mokhan.ca/blog/2007/12/18/Whats+Wrong+With+Inline+ASPX.aspx</link>
      <pubDate>Tue, 18 Dec 2007 20:42:36 GMT</pubDate>
      <description>&lt;p&gt;
This month I've been going pretty hard core about learning ASP.NET and I was having
a lot of difficulty with playing with the ASPX view engine. I'm already fairly familiar
with HTML and CSS, but now I have to learn these new ASP.NET controls? Why can't I
just stick to the HTML and CSS I know and enjoy working with?
&lt;/p&gt;
&lt;p&gt;
Well it turns out I can... I don't need to learn about the complex data binding of
a GridView or how an ASP:TextBox converts to a plain ol' input tag wrapped in span
tags. I've been heavily studying the work from the project we worked on during the &lt;a href="http://mokhan.ca/blog/2007/11/13/Photos+From+The+Nothin+But+NET+Boot+Camp.aspx"&gt;Nothin'
But .NET boot camp&lt;/a&gt; and reading up on the &lt;a href="http://support.microsoft.com/kb/307860#1a"&gt;MSDN
documentation on inlining aspx&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I like it... C'mon doesn't this....
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;h1&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Available
Slips&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;h1&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;table&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;thead&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Location
Name&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Dock
Name&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Slip
Width&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Slip
Length&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;thead&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt; &lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43,145,175)"&gt;SlipDisplayDTO&lt;/span&gt; item &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ViewLuggage&lt;/span&gt;.ClaimFor(&lt;span style="color: rgb(43,145,175)"&gt;ViewLuggageTickets&lt;/span&gt;.AvailableSlips)
) {&lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;=&lt;/span&gt; item.LocationName &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;a&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;href&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;='&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt;=
WebViews.DockView.Name( ) &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;?&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt;=
PayloadKeys.DockId &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;=&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt;=
item.DockId &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;'&amp;gt; &lt;/span&gt; &lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;=&lt;/span&gt; item.DockName &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;a&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;=&lt;/span&gt; item.Width &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;=&lt;/span&gt; item.Length &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt; } &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;table&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
Seem a lot more readable then this...
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;asp&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;:&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;Repeater&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;uxSlipsRepeater&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;server&amp;quot;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;HeaderTemplate&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;table&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;thead&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Dock
Name&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Slip
Width&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;Slip
Length&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;thead&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;HeaderTemplate&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;a&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;href&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;='DockView.aspx?&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt;=
PayLoadKeys.DockId &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;=&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;/span&gt;#
((SlipDisplayDTO)Container.DataItem).DockId &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;'&amp;gt; &lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;#&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Transform&lt;/span&gt;.From(Container.DataItem).AndConvertItToAn&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SlipDisplayDTO&lt;/span&gt;&amp;gt;().DockName &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt; &lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;a&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;#&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Transform&lt;/span&gt;.From(Container.DataItem).AndConvertItToAn&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SlipDisplayDTO&lt;/span&gt;&amp;gt;().Width &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: rgb(255,238,98)"&gt;&amp;lt;%&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;#&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Transform&lt;/span&gt;.From(Container.DataItem).AndConvertItToAn&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SlipDisplayDTO&lt;/span&gt;&amp;gt;().Length &lt;span style="background: rgb(255,238,98)"&gt;%&amp;gt;&lt;span style="color: rgb(0,0,255)"&gt;&lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;td&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt; &lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;tr&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;FooterTemplate&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;table&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;FooterTemplate&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;asp&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;:&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;Repeater&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;The extra asp namespaces appended
to all the controls just seem like noise. The explicit casting from Container.DataItem
to the type actually contained seems like extra work. I suppose you could write all
this out in an item data bound event handler. But it just looks like noise, noise
noise... Then when you actually look at the HTML that's spit out it loaded with more
noise...
&lt;/p&gt;
&lt;p&gt;
For example:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;ctl00$ContentPlaceHolder2$uxUserNameTextBox&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;id&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;ctl00_ContentPlaceHolder2_uxUserNameTextBox&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;font face="Courier New"&gt;&lt;/font&gt; 
&lt;p&gt;
Versus:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;uxUserNameTextBox&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255,0,0)"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Well all of this can be avoided. But
you're going to have to get just a little bit deeper, and here's how. Everything you
need to know is in &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.aspx"&gt;HttpContext&lt;/a&gt;.
Yup! 
&lt;/p&gt;
&lt;p&gt;
Instead of dropping an ASP:TextBox on the page try an &lt;a href="http://www.w3schools.com/tags/tag_input.asp"&gt;input
element&lt;/a&gt; and parse out the value in the input element from the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httprequest.params.aspx"&gt;HttpContext.Current.Request.Params&lt;/a&gt;.
This is a NameValueCollection that has all the Http Headers that were sent along the
trip to the server AKA &lt;a href="http://www.w3.org/TR/2003/WD-di-gloss-20030825/#def-http-payload-entity"&gt;The
Payload&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
For my current school assignment I'm currently flushing out the concept of an HttpGateway,
where all traffic comes in and all traffic goes out. Currently this is just wrapping
and HttpContext but with an interface that works better for me as a client of it.
I don't need to see everything available in the HttpContext (which is a lot!). 
&lt;/p&gt;
&lt;p&gt;
Next up, take advantage of the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.items.aspx"&gt;HttpContext.Items&lt;/a&gt; collection.
This is a collection of objects which you can load up with extra information to pass
on down the pipeline. Consider the concept of view luggage, where luggage is issued
a ticket when you drop it off. You can then claim that luggage using the same luggage
ticket.
&lt;/p&gt;
&lt;p&gt;
What does this mean, you can have your presenters, controllers, commands (whatever)
drop off luggage to be carried to the view. You can then have your views claim that
luggage with the luggage ticket. (Take a look back at the first bit of HTML markup
in this post.)
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.items.aspx"&gt;HttpContext.Items&lt;/a&gt; collection
is a dictionary for objects. Using strongly typed luggage tickets you can make that
the key, and the actual luggage the value to store in the items collection. The HttpContext
then becomes the airplane, carrier or transporter that hauls your luggage from your
presenter, controller, command (whatever) to the view.
&lt;/p&gt;
&lt;p&gt;
For the quick and dirty here's the code that describes what I'm talking about:
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ViewLuggageTransporter&lt;/span&gt;&amp;lt;
Luggage &amp;gt; : &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTransporter&lt;/span&gt;&amp;lt;
Luggage &amp;gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; ViewLuggageTransporter( &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTicket&lt;/span&gt;&amp;lt;
Luggage &amp;gt; key ) : &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;( key, &lt;span style="color: rgb(43,145,175)"&gt;HttpContext&lt;/span&gt;.Current.Items
) {} &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; ViewLuggageTransporter( &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTicket&lt;/span&gt;&amp;lt;
Luggage &amp;gt; key, &lt;span style="color: rgb(43,145,175)"&gt;IDictionary&lt;/span&gt; items )
{ _ticket = key; _items = items; } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; Luggage
Value() { &lt;span style="color: rgb(0,0,255)"&gt;foreach&lt;/span&gt; ( &lt;span style="color: rgb(43,145,175)"&gt;DictionaryEntry&lt;/span&gt; entry &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; _items
) { &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( entry.Key.Equals( _ticket ) ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; (
Luggage )entry.Value; } } &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;default&lt;/span&gt;(
Luggage ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; Add(
Luggage value ) { _items.Add( _ticket, value ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTicket&lt;/span&gt;&amp;lt;
Luggage &amp;gt; _ticket; &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IDictionary&lt;/span&gt; _items;
} &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ViewLuggage&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTransporter&lt;/span&gt;&amp;lt;
T &amp;gt; TransporterFor&amp;lt; T &amp;gt;( &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTicket&lt;/span&gt;&amp;lt;
T &amp;gt; ticket ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ViewLuggageTransporter&lt;/span&gt;&amp;lt;
T &amp;gt;( ticket ); } &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;static&lt;/span&gt; T
ClaimFor&amp;lt; T &amp;gt;( &lt;span style="color: rgb(43,145,175)"&gt;IViewLuggageTicket&lt;/span&gt;&amp;lt;
T &amp;gt; ticket ) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ViewLuggageTransporter&lt;/span&gt;&amp;lt;
T &amp;gt;( ticket ).Value( ); } }&lt;/pre&gt;
&lt;p&gt;
To parse out the value submitted in a request you can create mappers to parse out
the values for each control. In the code below each of the string literals prefixed
with a &amp;quot;ux&amp;quot; represents the name of the html control that was on the page.
&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;UpdateRegistrationPresentationMapper&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;IUpdateRegistrationPresentationMapper&lt;/span&gt; { &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;UpdateCustomerRegistrationDTO&lt;/span&gt; MapFrom( &lt;span style="color: rgb(43,145,175)"&gt;IHttpRequest&lt;/span&gt; input
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;UpdateCustomerRegistrationDTO&lt;/span&gt;(
input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.CustomerId
), input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.For( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;uxUserNameTextBox&amp;quot;&lt;/span&gt; )
), input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.For( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;uxPasswordTextBox&amp;quot;&lt;/span&gt; )
), input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.For( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;uxFirstNameTextBox&amp;quot;&lt;/span&gt; )
), input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.For( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;uxLastNameTextBox&amp;quot;&lt;/span&gt; )
), input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.For( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;uxPhoneNumberTextBox&amp;quot;&lt;/span&gt; )
), input.ParsePayloadFor( &lt;span style="color: rgb(43,145,175)"&gt;PayloadKeys&lt;/span&gt;.For( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;uxCityTextBox&amp;quot;&lt;/span&gt; )
) ); } }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
For an even sweeter example check out the source code for the &lt;a href="http://www.jpboodhoo.com/blog/codegooglecompjpboodhoo.aspx"&gt;NothinButDotNetStore&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
Next up, figuring out a cleaner way to implement authorization and authentication
without having to rely on the FormsAuthentication class. So far my spiking of Forms
Auth looks something like the code below... &lt;strong&gt;*Please do not use the code below.
I was just trying to understand how forms auth works and this is not a great example
of how you should use it.&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; AuthenticateHttpRequest(
) { &lt;span style="color: rgb(43,145,175)"&gt;HttpCookie&lt;/span&gt; cookie = GetCookieFrom( &lt;span style="color: rgb(43,145,175)"&gt;HttpContext&lt;/span&gt;.Current
); &lt;span style="color: rgb(0,0,255)"&gt;if&lt;/span&gt; ( &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt; !=
cookie ) { BindPrincipalToThreadUsing( _mapper.MapFrom( &lt;span style="color: rgb(43,145,175)"&gt;FormsAuthentication&lt;/span&gt;.Decrypt(
cookie.Value ) ) ); } } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;HttpCookie&lt;/span&gt; GetCookieFrom( &lt;span style="color: rgb(43,145,175)"&gt;HttpContext&lt;/span&gt; context
) { &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; context.Request.Cookies[ &lt;span style="color: rgb(43,145,175)"&gt;FormsAuthentication&lt;/span&gt;.FormsCookieName
]; } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; BindPrincipalToThreadUsing( &lt;span style="color: rgb(43,145,175)"&gt;CustomerCookieCredentials&lt;/span&gt; credentials
) { &lt;span style="color: rgb(43,145,175)"&gt;IIdentity&lt;/span&gt; identity = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;CustomerIdentity&lt;/span&gt;(
credentials.Username, credentials.Username ); &lt;span style="color: rgb(43,145,175)"&gt;HttpContext&lt;/span&gt;.Current.User
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;GenericPrincipal&lt;/span&gt;(
identity, &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;[]
{&lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;customer&amp;quot;&lt;/span&gt;} ); } &lt;span style="color: rgb(0,0,255)"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; AddAuthenticationTicket(
) { &lt;span style="color: rgb(43,145,175)"&gt;FormsAuthenticationTicket&lt;/span&gt; ticket = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;FormsAuthenticationTicket&lt;/span&gt;(
1, &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;mo&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;.Now, &lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;.Now.AddMinutes(
20 ), &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt;, &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;2&amp;quot;&lt;/span&gt; ); &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; cookieValue
= &lt;span style="color: rgb(43,145,175)"&gt;FormsAuthentication&lt;/span&gt;.Encrypt( ticket
); &lt;span style="color: rgb(43,145,175)"&gt;HttpContext&lt;/span&gt; current = &lt;span style="color: rgb(43,145,175)"&gt;HttpContext&lt;/span&gt;.Current;
current.Response.Cookies.Add( &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;HttpCookie&lt;/span&gt;( &lt;span style="color: rgb(43,145,175)"&gt;FormsAuthentication&lt;/span&gt;.FormsCookieName,
cookieValue ) ); &lt;span style="color: rgb(43,145,175)"&gt;IIdentity&lt;/span&gt; identity = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;CustomerIdentity&lt;/span&gt;( &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;mo&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;2&amp;quot;&lt;/span&gt; );
current.User = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;GenericPrincipal&lt;/span&gt;(
identity, &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;[]
{&lt;span style="color: rgb(163,21,21)"&gt;&amp;quot;customer&amp;quot;&lt;/span&gt;} ); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=c2a60fa5-162f-42c0-99a8-8542629fff07" /&gt;</description>
      <category>ASP NET</category>
      <category>CSharp</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=5acc438c-7589-438b-b0fc-6d56eb211b44</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,5acc438c-7589-438b-b0fc-6d56eb211b44.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
HTTP is used for so many different reasons. While working in the wold of point of
sale terminals, I spent some time sending raw HTTP packets and parsing them in C.
Lot's of fun!
</p>
        <p>
Here's a quick little exercise on playing with HTTP, that i found in "Microsoft .NET
Framework 2.0 Web-Based Client Development"
</p>
        <p>
1. Open up a command prompt: Start-&gt;Run-&gt;cmd 
</p>
        <p>
2. type "telnet", and press enter
</p>
        <p>
3. type "o mokhan.ca 80"
</p>
        <p>
4. type 
</p>
        <p>
"GET / HTTP/1.1 
</p>
        <p>
Host: mokhan.ca"
</p>
        <p>
Then press enter twice
</p>
        <p>
But do it quickly, before my server closes the connection due to a timeout!
</p>
        <p>
 
</p>
        <p>
          <table border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <img src="http://ec1.images-amazon.com/images/I/11RBAARA7DL.jpg" border="1" />
                </td>
                <td valign="top">
                  <b>MCTS Self-Paced Training Kit (Exam 70-528): Microsoft .NET Framework 2.0 Web-Based
Client Development (Pro Certification)</b>
                  <br />
by Glenn Johnson, Tony Northrup<br /><br /><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735623341%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735623341%253FSubscriptionId=0525E2PQ81DD7ZTWTK82">Read
more about this title...</a></td>
              </tr>
            </tbody>
          </table>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=5acc438c-7589-438b-b0fc-6d56eb211b44" />
      </body>
      <title>Understanding HTTP</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,5acc438c-7589-438b-b0fc-6d56eb211b44.aspx</guid>
      <link>http://mokhan.ca/blog/2007/07/02/Understanding+HTTP.aspx</link>
      <pubDate>Mon, 02 Jul 2007 23:27:51 GMT</pubDate>
      <description>&lt;p&gt;
HTTP is used for so many different reasons. While working in the wold of point of
sale terminals, I spent some time sending raw HTTP packets and parsing them in C.
Lot's of fun!
&lt;/p&gt;
&lt;p&gt;
Here's a quick little exercise on playing with HTTP, that i found in "Microsoft .NET
Framework 2.0 Web-Based Client Development"
&lt;/p&gt;
&lt;p&gt;
1. Open up a command prompt: Start-&amp;gt;Run-&amp;gt;cmd 
&lt;/p&gt;
&lt;p&gt;
2. type "telnet", and press enter
&lt;/p&gt;
&lt;p&gt;
3. type "o&amp;nbsp;mokhan.ca 80"
&lt;/p&gt;
&lt;p&gt;
4. type 
&lt;/p&gt;
&lt;p&gt;
"GET / HTTP/1.1 
&lt;/p&gt;
&lt;p&gt;
Host: mokhan.ca"
&lt;/p&gt;
&lt;p&gt;
Then press enter twice
&lt;/p&gt;
&lt;p&gt;
But do it quickly, before my server closes the connection due to a timeout!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;img src="http://ec1.images-amazon.com/images/I/11RBAARA7DL.jpg" border="1"&gt;&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;b&gt;MCTS Self-Paced Training Kit (Exam 70-528): Microsoft .NET Framework 2.0 Web-Based
Client Development (Pro Certification)&lt;/b&gt;
&lt;br&gt;
by Glenn Johnson, Tony Northrup&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html%3FASIN=0735623341%26tag=ws%26lcode=sp1%26cID=2025%26ccmID=165953%26location=/o/ASIN/0735623341%253FSubscriptionId=0525E2PQ81DD7ZTWTK82"&gt;Read
more about this title...&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=5acc438c-7589-438b-b0fc-6d56eb211b44" /&gt;</description>
      <category>ASP NET</category>
      <category>Books</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=ccdae224-3317-495b-84d4-c128d5ddbc92</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,ccdae224-3317-495b-84d4-c128d5ddbc92.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <p>
I gave this explanation to my wife last night on SMTP, so hopefully
it will help... 
</p>
        <p>
          <br />
SMTP stands for Simple Mail Transfer Protocol... you can think of it as a mailbox.
When you need to send mail to someone you put the mail in the mailbox, and a mail
person comes and picks up the mail and sends it to where ever it needs to go. 
</p>
        <p>
          <br />
Now pretend that we didn't have Canada Post to send our mail and in order to have
your mail sent you had to subscribe to a mail service, so that you had access to their
mail box, so that their mail person would come pick up the mail and deliver it
for you. 
</p>
        <p>
          <br />
I subscribe to Shaw cable, so they offer me their "mailbox" or SMTP server for me
to send all my outgoing mail through... If I want to send mail through GMail's
SMTP server I would need to have access to it. 
</p>
        <p>
          <br />
HTML Forms...
</p>
        <p>
There are many types of HTTP commands that are sent to a server the 2 most popular
are GET, POST.<br />
The GET verb requests a resource from the server, like a web page. 
<br />
The POST verb sends data to the server like in a contact form.
</p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=ccdae224-3317-495b-84d4-c128d5ddbc92" />
      </body>
      <title>HTTP Verbs and SMTP Over Simplified</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,ccdae224-3317-495b-84d4-c128d5ddbc92.aspx</guid>
      <link>http://mokhan.ca/blog/2007/06/27/HTTP+Verbs+And+SMTP+Over+Simplified.aspx</link>
      <pubDate>Wed, 27 Jun 2007 14:21:47 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I&amp;nbsp;gave this explanation to&amp;nbsp;my wife&amp;nbsp;last night on SMTP,&amp;nbsp;so&amp;nbsp;hopefully
it will help... 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
SMTP stands for Simple Mail Transfer Protocol... you can think of it as a mailbox.
When you need to send mail to someone you put the mail in the mailbox, and a mail
person&amp;nbsp;comes and picks up the mail and sends it to where ever it needs to go. 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
Now pretend that we didn't have Canada Post to send our mail and in order to have
your mail sent you had to subscribe to a mail service, so that you had access to their
mail box, so that their mail&amp;nbsp;person would come pick up the mail and deliver it
for you. 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
I subscribe to Shaw cable, so they offer me their "mailbox" or SMTP server for me
to send all my outgoing mail through... If I want to send mail through&amp;nbsp;GMail's
SMTP server I would&amp;nbsp;need to have access to it. 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
HTML Forms...
&lt;/p&gt;
&lt;p&gt;
There are many types of HTTP commands that are sent to a server the 2 most popular
are GET, POST.&lt;br&gt;
The GET verb requests a resource from the server, like a web page. 
&lt;br&gt;
The POST verb sends data to the server like in a contact form.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=ccdae224-3317-495b-84d4-c128d5ddbc92" /&gt;</description>
      <category>ASP NET</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=672c1d95-3c6e-4722-83cd-e769a18d3b6c</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,672c1d95-3c6e-4722-83cd-e769a18d3b6c.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just read an excellent <a href="http://www.jeffperrin.com/index.php/2007/06/04/obscuring-http/">article</a> on
feelings on ASP.NET. Although, I don't have as much experience with
ASP.NET as the author, I feel the same way about it. 
</p>
        <p>
Although, it gives us a lot of power, it is so much more bulkier then it could be.
The false sense of "state" that it provides us, and the way we have to program around
it, is odd. I much prefer the world of desktop application development for it's true
stateful environment, however I like the power of the web when it comes to communicating
messages to the world.
</p>
        <blockquote>
          <p>
"Now the first problem with Webforms is not that its an abstraction, or even that
its a leaky one (they all are). The problem is that what Webforms attempts to abstract
away is actually <em>simpler</em> than the abstraction!" - Jeff Perrin
</p>
        </blockquote>
        <p>
It's odd how many so called ASP.NET developers couldn't write the simplest HTML. It
seems the concept of standards compliance, and html validation is not of
importance. Why?
</p>
        <p>
(Do me a favor and stop writing so much of your heavy business logic write into the
code behind of your web forms and custom controls. Do you have any idea how difficult
it is to make a simple change?)
</p>
        <p>
          <a title="Obscuring HTTP" href="http://www.jeffperrin.com/index.php/2007/06/04/obscuring-http/">Obscuring
HTTP</a>
        </p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=672c1d95-3c6e-4722-83cd-e769a18d3b6c" />
      </body>
      <title>Stop Pretending ASP.NET</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,672c1d95-3c6e-4722-83cd-e769a18d3b6c.aspx</guid>
      <link>http://mokhan.ca/blog/2007/06/05/Stop+Pretending+ASPNET.aspx</link>
      <pubDate>Tue, 05 Jun 2007 17:56:37 GMT</pubDate>
      <description>&lt;p&gt;
I just read an excellent &lt;a href="http://www.jeffperrin.com/index.php/2007/06/04/obscuring-http/"&gt;article&lt;/a&gt; on
feelings on&amp;nbsp;ASP.NET. Although, I don't have&amp;nbsp;as much&amp;nbsp;experience with
ASP.NET as the author, I feel the same way about it. 
&lt;/p&gt;
&lt;p&gt;
Although, it gives us a lot of power, it is so much more bulkier then it could be.
The false sense of "state" that it provides us, and the way we have to program around
it, is odd. I much prefer the world of desktop application development for it's true
stateful environment, however I like the power of the web when it comes to communicating
messages to the world.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"Now the first problem with Webforms is not that its an abstraction, or even that
its a leaky one (they all are). The problem is that what Webforms attempts to abstract
away is actually &lt;em&gt;simpler&lt;/em&gt; than the abstraction!" - Jeff Perrin
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
It's odd how many so called ASP.NET developers couldn't write the simplest HTML. It
seems&amp;nbsp;the concept of standards compliance, and html&amp;nbsp;validation is not of
importance. Why?
&lt;/p&gt;
&lt;p&gt;
(Do me a favor and stop writing so much of your heavy business logic write into the
code behind of your web forms and custom controls. Do you have any idea how difficult
it is to make a simple change?)
&lt;/p&gt;
&lt;p&gt;
&lt;a title="Obscuring HTTP" href="http://www.jeffperrin.com/index.php/2007/06/04/obscuring-http/"&gt;Obscuring
HTTP&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=672c1d95-3c6e-4722-83cd-e769a18d3b6c" /&gt;</description>
      <category>ASP NET</category>
    </item>
    <item>
      <trackback:ping>http://mokhan.ca/blog/Trackback.aspx?guid=f1375790-656e-4c7f-a6d4-8237c14400cc</trackback:ping>
      <pingback:server>http://mokhan.ca/blog/pingback.aspx</pingback:server>
      <pingback:target>http://mokhan.ca/blog/PermaLink,guid,f1375790-656e-4c7f-a6d4-8237c14400cc.aspx</pingback:target>
      <dc:creator />
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div class="introblock">
          <b>AJAX</b>, shorthand for <b><a title="Asynchronous" href="http://en.wikipedia.org/wiki/Asynchronous">Asynchronous</a><a title="JavaScript" href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> and <a title="XML" href="http://en.wikipedia.org/wiki/XML">XML</a></b>,
is a <a title="World Wide Web" href="http://en.wikipedia.org/wiki/World_Wide_Web">Web</a> development
technique for creating interactive <a title="Web application" href="http://en.wikipedia.org/wiki/Web_application">web
applications</a>. The intent is to make web pages feel more responsive by exchanging
small amounts of data with the server behind the scenes, so that the entire web page
does not have to be reloaded each time the user makes a change. This is meant to increase
the web page's interactivity, speed, and <a title="Usability" href="http://en.wikipedia.org/wiki/Usability">usability</a>."
- <a href="http://en.wikipedia.org/wiki/AJAX">wikipedia</a></div>
        <p>
There are 3 main components in my AJAX implementation. The client side JavaScript
and HTML, and the server side AJAX call processor. For this articles I am going to
discuss how I implemented the <a href="../blog_home.html">blog</a> page on this site
using AJAX.
</p>
        <h2>Client Side
</h2>
        <p>
If you check the source code behind my blog page you may notice 2 script files were
included. These are "ajax_obj.js" and "getEntry.js". The "ajax_obj.js" file creates
an instance of the "XMLHttpRequest" object for non Microsoft browsers and an "ActiveXObject"
for Microsoft web browsers. This object is pretty cool, it's the basis for almost
all AJAX technology. Learn it, understand it and AJAX will become a breeze.
</p>
        <div class="center comment">
          <a href="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_obj%5B2%5D.jpg" atomicselection="true">
            <img style="border-width: 0px;" alt="AJAX Base Object" src="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_obj_thumb.jpg" border="0" height="405" width="687" />
          </a>
        </div>
        <p>
The 2nd js file, "getEntry.js" performs the interaction between my web server and
the client machine (You're the client by the way!). What it does is sends a request
to my server for my latest blog entry, my server takes the request and returns just
the blog entry. Duh!
</p>
        <div class="center comment"> <a href="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/getEntry%5B2%5D.jpg" atomicselection="true"><img style="border-width: 0px;" alt="Retrieve Blog Entry" src="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/getEntry_thumb.jpg" border="0" height="471" width="551" /></a></div>
        <p>
But how does it do this? Using the "XMLHttpRequest" or "ActiveXObject" object instantiated
in the "ajax_obj.js" file we use 4 methods/properties. To make this easy let's call
this guy "goAJAXReq", short for global AJAX request object.
</p>
        <ul>
          <li>
            <strong>open:</strong> This specifies what type of request I would like to make the
server, and what URL to call. 
</li>
          <li>
            <strong>onreadystatechange:</strong> This specifies a "callback" function to handle
the servers response to my request. The callback is basically a function created in
order to receive the call back. It's like leaving a voicemail message on your buddy's
phone and telling him to call you back at this number when he gets the message. 
</li>
          <li>
            <strong>send:</strong> This tells the "goAJAXReq" to send the request to the server.
Kind of like picking up the phone to call your buddy. Except like me your buddy never
answers the phone so you'll have to leave a message. 
</li>
          <li>
            <strong>status:</strong> This tells you the status of your request so far. It's actually
and HTTP status, and would be similar to an operator message. "This number cannot
be reached. Please try again!" If you don't get this message most people here a "Hello!?"
on the other end. The "Hello" is a 404 status. The operator message is like the HTTP
200 or 404 status. 
</li>
        </ul>
        <p>
"getEntry()" function. This guy dials the phone number, leaves a message with a "callback"
number and pressed # to send the message. 
</p>
        <p>
"updatePage()" is the number buddy can call me back at. So when buddy calls me I answer
at this number and he gives me the info that I need. When I receive my blog entry
back from my server I search for an HTML element on the page called "blog". This is
defined as a &lt;div&gt; tag, and I write the data returned back to me in this element.
Voila, that's the AJAX on the client side. Now you can go into a lot more detail with
how you would like your data sent to you, and how you would like it packaged and unpackaged.
But for this example, my call returned straight forward HTML for my blog entry.
</p>
        <h2>Server Side
</h2>
        <p>
The server side implementation can be done in so many different ways. Most of the
AJAX articles I found on the net used PHP, for this example I am using ASP.NET. The
key component in my implementation is the use of "reflection". My AJAX object "goAJAXReq"
sends the method name it wishes to run at the server to return the data it wants.
In this example the method was "getEntry". Using reflection I parse out the value
for the method variable and call that function. This function grabs my latest blog
entry, makes sure its valid HTML and returns the data to the client.
</p>
        <div class="center comment"> <a href="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_call_class%5B2%5D.jpg" atomicselection="true"><img style="border-width: 0px;" alt="AJAX Call Class" src="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_call_class_thumb.jpg" border="0" height="530" width="685" /></a></div>
        <p>
In my AJAX call class I parse out the value for the "method" variable from the request
stream. I am using the "method" variable to contain the name of the method I want
to invoke. In this example the request stream is sending "method=getEntry". This means
the request stream wishes to process the "getEntry" method on the server. After parsing
our the "getEntry" name I use reflection to call that method. My "getEntry" method
grabs my latest blog entry and writes it directly to the "response" stream. This is
what carries the data being transferred back to the client.
</p>
        <p>
Voila! My AJAX call processor is complete. If you have any questions at all please <a title="Contact Me" href="../contact.html">contact
me!</a></p>
        <img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=f1375790-656e-4c7f-a6d4-8237c14400cc" />
      </body>
      <title>AJAX Call Processor with ASP.NET</title>
      <guid isPermaLink="false">http://mokhan.ca/blog/PermaLink,guid,f1375790-656e-4c7f-a6d4-8237c14400cc.aspx</guid>
      <link>http://mokhan.ca/blog/2006/07/01/AJAX+Call+Processor+With+ASPNET.aspx</link>
      <pubDate>Sat, 01 Jul 2006 04:17:35 GMT</pubDate>
      <description>&lt;div class="introblock"&gt;&lt;b&gt;AJAX&lt;/b&gt;, shorthand for &lt;b&gt;&lt;a title="Asynchronous" href="http://en.wikipedia.org/wiki/Asynchronous"&gt;Asynchronous&lt;/a&gt; &lt;a title="JavaScript" href="http://en.wikipedia.org/wiki/JavaScript"&gt;JavaScript&lt;/a&gt; and &lt;a title="XML" href="http://en.wikipedia.org/wiki/XML"&gt;XML&lt;/a&gt;&lt;/b&gt;,
is a &lt;a title="World Wide Web" href="http://en.wikipedia.org/wiki/World_Wide_Web"&gt;Web&lt;/a&gt; development
technique for creating interactive &lt;a title="Web application" href="http://en.wikipedia.org/wiki/Web_application"&gt;web
applications&lt;/a&gt;. The intent is to make web pages feel more responsive by exchanging
small amounts of data with the server behind the scenes, so that the entire web page
does not have to be reloaded each time the user makes a change. This is meant to increase
the web page's interactivity, speed, and &lt;a title="Usability" href="http://en.wikipedia.org/wiki/Usability"&gt;usability&lt;/a&gt;."
- &lt;a href="http://en.wikipedia.org/wiki/AJAX"&gt;wikipedia&lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;
There are 3 main components in my AJAX implementation. The client side JavaScript
and HTML, and the server side AJAX call processor. For this articles I am going to
discuss how I implemented the &lt;a href="../blog_home.html"&gt;blog&lt;/a&gt; page on this site
using AJAX.
&lt;/p&gt;
&lt;h2&gt;Client Side
&lt;/h2&gt;
&lt;p&gt;
If you check the source code behind my blog page you may notice 2 script files were
included. These are "ajax_obj.js" and "getEntry.js". The "ajax_obj.js" file creates
an instance of the "XMLHttpRequest" object for non Microsoft browsers and an "ActiveXObject"
for Microsoft web browsers. This object is pretty cool, it's the basis for almost
all AJAX technology. Learn it, understand it and AJAX will become a breeze.
&lt;/p&gt;
&lt;div class="center comment"&gt;&lt;a href="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_obj%5B2%5D.jpg" atomicselection="true"&gt;&lt;img style="border-width: 0px;" alt="AJAX Base Object" src="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_obj_thumb.jpg" border="0" height="405" width="687"&gt;&lt;/a&gt; 
&lt;/div&gt;
&lt;p&gt;
The 2nd js file, "getEntry.js" performs the interaction between my web server and
the client machine (You're the client by the way!). What it does is sends a request
to my server for my latest blog entry, my server takes the request and returns just
the blog entry. Duh!
&lt;/p&gt;
&lt;div class="center comment"&gt;&amp;nbsp;&lt;a href="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/getEntry%5B2%5D.jpg" atomicselection="true"&gt;&lt;img style="border-width: 0px;" alt="Retrieve Blog Entry" src="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/getEntry_thumb.jpg" border="0" height="471" width="551"&gt;&lt;/a&gt; 
&lt;/div&gt;
&lt;p&gt;
But how does it do this? Using the "XMLHttpRequest" or "ActiveXObject" object instantiated
in the "ajax_obj.js" file we use 4 methods/properties. To make this easy let's call
this guy "goAJAXReq", short for global AJAX request object.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;open:&lt;/strong&gt; This specifies what type of request I would like to make the
server, and what URL to call. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;onreadystatechange:&lt;/strong&gt; This specifies a "callback" function to handle
the servers response to my request. The callback is basically a function created in
order to receive the call back. It's like leaving a voicemail message on your buddy's
phone and telling him to call you back at this number when he gets the message. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;send:&lt;/strong&gt; This tells the "goAJAXReq" to send the request to the server.
Kind of like picking up the phone to call your buddy. Except like me your buddy never
answers the phone so you'll have to leave a message. 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;status:&lt;/strong&gt; This tells you the status of your request so far. It's actually
and HTTP status, and would be similar to an operator message. "This number cannot
be reached. Please try again!" If you don't get this message most people here a "Hello!?"
on the other end. The "Hello" is a 404 status. The operator message is like the HTTP
200 or 404 status. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
"getEntry()" function. This guy dials the phone number, leaves a message with a "callback"
number and pressed # to send the message. 
&lt;/p&gt;
&lt;p&gt;
"updatePage()" is the number buddy can call me back at. So when buddy calls me I answer
at this number and he gives me the info that I need. When I receive my blog entry
back from my server I search for an HTML element on the page called "blog". This is
defined as a &amp;lt;div&amp;gt; tag, and I write the data returned back to me in this element.
Voila, that's the AJAX on the client side. Now you can go into a lot more detail with
how you would like your data sent to you, and how you would like it packaged and unpackaged.
But for this example, my call returned straight forward HTML for my blog entry.
&lt;/p&gt;
&lt;h2&gt;Server Side
&lt;/h2&gt;
&lt;p&gt;
The server side implementation can be done in so many different ways. Most of the
AJAX articles I found on the net used PHP, for this example I am using ASP.NET. The
key component in my implementation is the use of "reflection". My AJAX object "goAJAXReq"
sends the method name it wishes to run at the server to return the data it wants.
In this example the method was "getEntry". Using reflection I parse out the value
for the method variable and call that function. This function grabs my latest blog
entry, makes sure its valid HTML and returns the data to the client.
&lt;/p&gt;
&lt;div class="center comment"&gt;&amp;nbsp;&lt;a href="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_call_class%5B2%5D.jpg" atomicselection="true"&gt;&lt;img style="border-width: 0px;" alt="AJAX Call Class" src="http://mokhan.ca/Blog/content/binary/WindowsLiveWriter/e66d60424b6a_13843/ajax_call_class_thumb.jpg" border="0" height="530" width="685"&gt;&lt;/a&gt; 
&lt;/div&gt;
&lt;p&gt;
In my AJAX call class I parse out the value for the "method" variable from the request
stream. I am using the "method" variable to contain the name of the method I want
to invoke. In this example the request stream is sending "method=getEntry". This means
the request stream wishes to process the "getEntry" method on the server. After parsing
our the "getEntry" name I use reflection to call that method. My "getEntry" method
grabs my latest blog entry and writes it directly to the "response" stream. This is
what carries the data being transferred back to the client.
&lt;/p&gt;
&lt;p&gt;
Voila! My AJAX call processor is complete. If you have any questions at all please &lt;a title="Contact Me" href="../contact.html"&gt;contact
me!&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://mokhan.ca/blog/aggbug.ashx?id=f1375790-656e-4c7f-a6d4-8237c14400cc" /&gt;</description>
      <category>ASP NET</category>
      <category>CSharp</category>
    </item>
  </channel>
</rss>