<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emad Ibrahim &#187; ASP.NET</title>
	<atom:link href="http://www.emadibrahim.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emadibrahim.com</link>
	<description>web development, tech reviews, tips, tricks, blogging</description>
	<lastBuildDate>Mon, 03 May 2010 12:27:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ASP.NET MVC &amp; Threads</title>
		<link>http://www.emadibrahim.com/2008/07/01/aspnet-mvc-threads/</link>
		<comments>http://www.emadibrahim.com/2008/07/01/aspnet-mvc-threads/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 21:15:29 +0000</pubDate>
		<dc:creator>Emad Ibrahim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.emadibrahim.com/?p=427</guid>
		<description><![CDATA[I have a method that handles sending of emails.&#160; I wrote it so that it would run asynchronously, so that it won&#8217;t slow down the web app.&#160; It looks like this: protected static void SendMail(string to, string subject, string body) { try { using (var bgw = new BackgroundWorker()) { bgw.DoWork += new DoWorkEventHandler(delegate { [...]]]></description>
			<content:encoded><![CDATA[<p>I have a method that handles sending of emails.&nbsp; I wrote it so that it would run asynchronously, so that it won&#8217;t slow down the web app.&nbsp; It looks like this:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> SendMail(<span style="color: #0000ff">string</span> to, <span style="color: #0000ff">string</span> subject, <span style="color: #0000ff">string</span> body)
{
    <span style="color: #0000ff">try</span>
    {
        <span style="color: #0000ff">using</span> (var bgw = <span style="color: #0000ff">new</span> BackgroundWorker())
        {
            bgw.DoWork += <span style="color: #0000ff">new</span> DoWorkEventHandler(<span style="color: #0000ff">delegate</span>
                                                     {
                                                         <span style="color: #0000ff">try</span>
                                                         {
                                                             Thread.Sleep(15000);
                                                             <span style="color: #0000ff">using</span> (MailMessage message = <span style="color: #0000ff">new</span> MailMessage())
                                                             {
                                                                 message.From = <span style="color: #0000ff">new</span> MailAddress(AdminEmail,
                                                                                                AdminName);
                                                                 message.To.Add(<span style="color: #0000ff">new</span> MailAddress(to));
                                                                 message.Subject = subject;
                                                                 message.Body = body;
                                                                 message.IsBodyHtml = <span style="color: #0000ff">false</span>;

                                                                 SmtpClient mailClient = <span style="color: #0000ff">new</span> SmtpClient();
                                                                 mailClient.Send(message);
                                                             }
                                                         }
                                                         <span style="color: #0000ff">catch</span> (Exception ex)
                                                         {
                                                             Utils.Log(ex);
                                                         }
                                                     });

            bgw.RunWorkerAsync();
        }
    }
    <span style="color: #0000ff">catch</span> (Exception ex)
    {
        Utils.Log(ex);
    }
}</pre>
</div>
<p>I added the Thread.Sleep(15000) to see if it works.&nbsp; To my surprise, it didn&#8217;t.&nbsp; For some reason, the web request doesn&#8217;t return until the email thread is done executing.&nbsp; When I step through the code, it runs through the code right away without waiting and calls the return method on the controller as expected.&nbsp; But the response is actually never sent to the server until the thread completes &#8211; which defies the whole point of it being asynchronous.</p>
<p>What am I doing wrong?&nbsp; Is this a bug in the MVC framework?&nbsp; Or did I just overlook something?</p>
<p><strong>[UPDATE]</strong></p>
<p>I am not sure what&#8217;s wrong with the code above but I re-wrote it as show below and it works very well.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> SendMail(<span style="color: #0000ff">string</span> to, <span style="color: #0000ff">string</span> subject, <span style="color: #0000ff">string</span> body)
{
   <span style="color: #0000ff">try</span>
   {
       var t1 = <span style="color: #0000ff">new</span> Thread(SendMailAsync);
       t1.Start(<span style="color: #0000ff">new</span> <span style="color: #0000ff">string</span>[] {to, subject, body});
   }
   <span style="color: #0000ff">catch</span> (Exception ex)
   {
       Utils.Log(ex);
   }
}

<span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> SendMailAsync(<span style="color: #0000ff">object</span> emailInfo)
{
   <span style="color: #0000ff">try</span>
   {

       var paramArray = emailInfo <span style="color: #0000ff">as</span> <span style="color: #0000ff">string</span>[];
       <span style="color: #0000ff">if</span> (paramArray != <span style="color: #0000ff">null</span>)
       {
           var to = paramArray[0];
           var subject = paramArray[1];
           var body = paramArray[2];

           <span style="color: #0000ff">using</span> (MailMessage message = <span style="color: #0000ff">new</span> MailMessage())
           {
               message.From = <span style="color: #0000ff">new</span> MailAddress(AdminEmail,
                                              AdminName);
               message.To.Add(<span style="color: #0000ff">new</span> MailAddress(to));
               message.Subject = subject;
               message.Body = body;
               message.IsBodyHtml = <span style="color: #0000ff">false</span>;

               var mailClient = <span style="color: #0000ff">new</span> SmtpClient();
               mailClient.Send(message);
           }
       }
   }
   <span style="color: #0000ff">catch</span> (Exception ex)
   {
       Utils.Log(ex);
   }
}</pre>
</div>
<div class="aizattos_related_posts"><span class="aizattos_related_posts_header" >Related Posts</span><ul><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/01/05/resolving-url-in-aspnet-using-tilda/" rel="bookmark" title="Permanent Link: Resolving URL in ASP.net using Tilda (~)" >Resolving URL in ASP.net using Tilda (~)</a></span><div class="aizattos_related_posts_excerpt">I have been using .net since it has come out and I just found this out (so, I am kind of pissed).  W...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/01/11/aspnet-20-error-title-is-not-a-member-of-asp%e2%80%a6/" rel="bookmark" title="Permanent Link: asp.net 2.0 Error: &#8216;Title&#8217; is not a member of &#8216;ASP…" >asp.net 2.0 Error: &#8216;Title&#8217; is not a member of &#8216;ASP…</a></span><div class="aizattos_related_posts_excerpt">I had this error come up on a few pages after I deployed my website and it was driving me crazy.  Af...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/03/31/ajax-with-aspnet-mvc-framework-preview-2/" rel="bookmark" title="Permanent Link: Ajax with ASP.NET MVC Framework Preview 2" >Ajax with ASP.NET MVC Framework Preview 2</a></span><div class="aizattos_related_posts_excerpt">This is the updated version of the Nikhil's excellent example on how to use Ajax with ASP.net MVC.
...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/04/11/yonkly-open-source-twitter/" rel="bookmark" title="Permanent Link: Yonkly &#8211; Open Source Twitter" >Yonkly &#8211; Open Source Twitter</a></span></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/09/07/deciding-between-aspnet-mvc-and-webforms/" rel="bookmark" title="Permanent Link: Deciding Between ASP.NET MVC and WebForms" >Deciding Between ASP.NET MVC and WebForms</a></span></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emadibrahim.com/2008/07/01/aspnet-mvc-threads/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CMAP Code Camp 2008 Spring Edition</title>
		<link>http://www.emadibrahim.com/2008/04/13/cmap-code-camp-2008-spring-edition/</link>
		<comments>http://www.emadibrahim.com/2008/04/13/cmap-code-camp-2008-spring-edition/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 23:36:35 +0000</pubDate>
		<dc:creator>Emad Ibrahim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[cmap]]></category>
		<category><![CDATA[codecamp]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.emadibrahim.com/2008/04/13/cmap-code-camp-2008-spring-edition/</guid>
		<description><![CDATA[Yesterday, I gave a talk at CMAP Code Camp about the asp.net mvc framework and AJAX using JQuery. This is my first time speaking, so I was a little nervous. I think I did ok but I can&#8217;t really tell. Of course, the talk didn&#8217;t go as planned, because Visual Studio didn&#8217;t cooperate. Thankfully, I [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I gave a talk at <a href="http://www.cmap-online.org/CodeCamp/">CMAP Code Camp</a> about the asp.net mvc framework and AJAX using JQuery.  This is my first time speaking, so I was a little nervous.  I think I did ok but I can&#8217;t really tell.  Of course, the talk didn&#8217;t go as planned, because Visual Studio didn&#8217;t cooperate.  Thankfully, I had a Plan B and pulled up code that I had already prepared and just walked through it and explained it.  I wanted to give more details but I didn&#8217;t have enough time.</p>
<p>So, if you have attended the talk, I would love to hear your feedback, so please leave me a comment or send me a not through the <a href="http://www.emadibrahim.com/contact/">contact</a> page.</p>
<p>Previously, I posted some asp.net mvc framework resources over <a href="http://www.emadibrahim.com/2008/04/04/unit-test-linq-to-sql-in-aspnet-mvc-with-moq/">here</a>.  You can also see my mvc bookmarks at <a title="http://del.icio.us/eibrahim/mvc" href="http://del.icio.us/eibrahim/mvc">http://del.icio.us/eibrahim/mvc</a></p>
<p>There are also tons of JQuery resources at <a href="http://www.jquery.com">www.jquery.com</a> and I found this handy JQuery 1.2 cheat sheet (<strong><span style="text-decoration: underline;">remember</span></strong>: this is for version 1.2)<br/></p>
<div style="display: none">
<script>document.write('<noscript>');</script><br />
<noscript><noscript></noscript><br />
<script src="http://www.scribd.com/javascripts/view.js" type="text/javascript"></script>
</div>
<div id="embedded_flash_2093417_ie0ue" style="width: 100%; height: 100%">
<div style="width: 100%; height: 100%">
<object id="embedded_flash_2093417_ie0ue_embed4665116856" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="370" width="450" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="embedded_flash_2093417_ie0ue_embed4665116856"><param name="_cx" value="11906"><param name="_cy" value="9790"><param name="FlashVars" value=""><param name="Movie" value="http://documents.scribd.com/ScribdViewer.swf"><param name="Src" value="http://documents.scribd.com/ScribdViewer.swf"><param name="WMode" value="Opaque"><param name="Play" value="0"><param name="Loop" value="-1"><param name="Quality" value="High"><param name="SAlign" value=""><param name="Menu" value="-1"><param name="Base" value=""><param name="AllowScriptAccess" value="always"><param name="Scale" value="ShowAll"><param name="DeviceFont" value="0"><param name="EmbedMovie" value="0"><param name="BGColor" value="FFFFFF"><param name="SWRemote" value=""><param name="MovieData" value=""><param name="SeamlessTabbing" value="1"><param name="Profile" value="0"><param name="ProfileAddress" value=""><param name="ProfilePort" value="0"><param name="AllowNetworking" value="all"><param name="AllowFullScreen" value="true"></object></div>
</div>
<div style="display: none">
<script type="text/javascript"> var scribd_doc = new scribd.Document(2093417, 'key-r2kryjbgk3xe6r92w2k'); scribd_doc.addParam('height', 370); scribd_doc.addParam('width', 450); scribd_doc.addParam('page', 1); scribd_doc.addParam('mode', 'list'); scribd_doc.write('embedded_flash_2093417_ie0ue');</script>
</div>
<p>
&#8220;According to most studies, people&#8217;s number one fear is public speaking. Number two is death. Death is number two. Does that sound right? This means to the average person, if you go to a funeral, you&#8217;re better off in the casket than doing the eulogy.&#8221; &#8211; Jerry Seinfeld.</p>
<div class="aizattos_related_posts"><span class="aizattos_related_posts_header" >Related Posts</span><ul><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/06/27/free-it-consultation-in-the-dc-metro-area/" rel="bookmark" title="Permanent Link: Free IT Consultation in the DC Metro Area" >Free IT Consultation in the DC Metro Area</a></span><div class="aizattos_related_posts_excerpt">I have been busy working on several things since I quit my job.&nbsp; Things like the open source tw...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/08/18/the-best-ioc-container/" rel="bookmark" title="Permanent Link: The Best IoC Container?" >The Best IoC Container?</a></span><div class="aizattos_related_posts_excerpt">As I previously mentioned in my post "The Best JavaScript Library", I am in the process of developin...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/05/02/ruby-on-rails-crumbs-part-1/" rel="bookmark" title="Permanent Link: Ruby on Rails Crumbs &#8211; Part 1" >Ruby on Rails Crumbs &#8211; Part 1</a></span><div class="aizattos_related_posts_excerpt">If you have been following along, I blogged previously about my experience trying Ruby on Rails as a...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/04/07/learning-php/" rel="bookmark" title="Permanent Link: Learning PHP" >Learning PHP</a></span></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/05/09/yonkly-updated-05092008/" rel="bookmark" title="Permanent Link: Yonkly: Updated 05/09/2008" >Yonkly: Updated 05/09/2008</a></span></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emadibrahim.com/2008/04/13/cmap-code-camp-2008-spring-edition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Yonkly &#8211; Open Source Twitter</title>
		<link>http://www.emadibrahim.com/2008/04/11/yonkly-open-source-twitter/</link>
		<comments>http://www.emadibrahim.com/2008/04/11/yonkly-open-source-twitter/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 17:25:13 +0000</pubDate>
		<dc:creator>Emad Ibrahim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Yonkly]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.emadibrahim.com/2008/04/11/yonkly-open-source-twitter/</guid>
		<description><![CDATA[[update: Yonkly source code is now public] [update 2: I just created www.isweat.com using the yonkly engine] [update 3: Tons of new features] Asp.net MVC framework rocks. I wanted to play with it more and decided why not build an open source twitter. Unfortunately, I couldn&#8217;t come up with a better name for it that had [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>update</strong>: Yonkly source code is now <a href="../2008/05/29/yonkly-source-code/" target="_blank">public</a>]</p>
<p>[<strong>update 2</strong>: I just created <a href="http://www.isweat.com">www.isweat.com</a> using the yonkly engine]</p>
<p>[<strong>update 3:</strong> Tons of new <a href="http://www.emadibrahim.com/2008/10/01/major-update-to-yonkly-widgets-ads-more/">features</a>]</p>
<p>Asp.net MVC framework rocks.  I wanted to play with it more and decided why not build an open source twitter.  Unfortunately, I couldn&#8217;t come up with a better name for it that had an available domain so Yonkly it is.  Come to think of it Yonkly is not too bad &#8211; <a href="http://yonkly.com">http://yonkly.com</a></p>
<p>I will post the source code online very soon at either codeplex or Google &#8211; not sure which one is better yet.  Any suggestions?  I just need to clean it up and add some comments before I post it online.  Hopefully, no one will laugh at my code.</p>
<p>This first release has the following features (Note: this is only <strong>one</strong> week&#8217;s worth of work):</p>
<ol>
<li>Conversation threads &#8211; here is an <a href="http://www.yonkly.com/message/conversation/87">example</a><br />
<a href="http://www.yonkly.com/message/conversation/87"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://www.emadibrahim.com/wp-content/uploads/2008/04/windowslivewriteryonklyopensourcetwitter-8f3dimage-5.png" border="0" alt="image" width="436" height="307" /></a></li>
<li>Message replies automatically turn into a conversation, just hit the reply button <a href="http://www.emadibrahim.com/wp-content/uploads/2008/04/windowslivewriteryonklyopensourcetwitter-8f3dimage-2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.emadibrahim.com/wp-content/uploads/2008/04/windowslivewriteryonklyopensourcetwitter-8f3dimage-thumb.png" border="0" alt="image" width="26" height="29" /></a></li>
<li>Message deletes &#8211; cannot delete messages that have been replied to.</li>
<li>Follow and Un-follow friends</li>
<li>Built-in URL shortening</li>
<li>Public timeline</li>
<li>Friends and followers stats</li>
<li>Integration with Gravatar (<a href="http://www.gravatar.com">www.gravatar.com</a>)</li>
<li>Search for friends by email or username</li>
<li>Invite friends</li>
</ol>
<p>Depending on community support and involvement, I am hopping to add the following features in the next release(s):</p>
<ol>
<li>REST API</li>
<li>RSS feeds</li>
<li>Twitter and Facebook integration</li>
<li>Expanded user profile</li>
<li>Friend finder &#8211; using gmail, hotmail, outlook imports, etc&#8230;</li>
<li>Email notifications with opt-in/opt-out options</li>
<li>Silverlight, Windows, mac and mobile clients (require the API)</li>
<li>Migrate to SQL Server standard</li>
<li>UI changes and improvements</li>
</ol>
<p>The following was used to build the site:</p>
<ol>
<li>Asp.net 3.5 MVC Framework Preview 2</li>
<li>JQuery for JavaScript and Ajax</li>
<li>SQL Server Express</li>
</ol>
<p>This was an excellent learning experience which was only possible because of all the MVC fans, bloggers and community.  These are all my mvc-related bookmarks that I kept referring to during the development process &#8211; <a title="http://del.icio.us/eibrahim/mvc" href="http://del.icio.us/eibrahim/mvc">http://del.icio.us/eibrahim/mvc</a></p>
<h2>FUN STUFF</h2>
<p>How about becoming part of this open source project?  If you are interested, leave a comment below or contact me via the contact page.  Also, subscribe to my blog to get notified of updates, new releases and so on.</p>
<p>You can also find me on yonkly at <a href="http://yonkly.com/eibrahim">yonkly.com/eibrahim</a> or twitter (how ironic) at <a href="http://www.twitter.com/eibrahim">twitter.com/eibrahim</a></p>
<div class="aizattos_related_posts"><span class="aizattos_related_posts_header" >Related Posts</span><ul><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/05/29/yonkly-source-code/" rel="bookmark" title="Permanent Link: Yonkly Source Code" >Yonkly Source Code</a></span><div class="aizattos_related_posts_excerpt">[UPDATE] Source code is now available in codeplex at http://www.codeplex.com/yonkly

I apologize f...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2009/01/08/yonkly-source-code-for-sale/" rel="bookmark" title="Permanent Link: Yonkly Source Code For Sale" >Yonkly Source Code For Sale</a></span><div class="aizattos_related_posts_excerpt">You can now buy the best twitter-clone software out there complete with full source code for your cu...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/05/09/yonkly-updated-05092008/" rel="bookmark" title="Permanent Link: Yonkly: Updated 05/09/2008" >Yonkly: Updated 05/09/2008</a></span><div class="aizattos_related_posts_excerpt">[update: Yonkly source code is now public]

We just released a new updated version younkly that is...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/07/25/web-design-toolbox/" rel="bookmark" title="Permanent Link: Web Design Toolbox" >Web Design Toolbox</a></span></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/11/10/yonkly-making-progress/" rel="bookmark" title="Permanent Link: Yonkly Making Progress" >Yonkly Making Progress</a></span></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emadibrahim.com/2008/04/11/yonkly-open-source-twitter/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>Tricky Asp.net MVC URL Rewriting</title>
		<link>http://www.emadibrahim.com/2008/04/10/tricky-aspnet-mvc-url-rewriting/</link>
		<comments>http://www.emadibrahim.com/2008/04/10/tricky-aspnet-mvc-url-rewriting/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 23:38:33 +0000</pubDate>
		<dc:creator>Emad Ibrahim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[url rewriting]]></category>

		<guid isPermaLink="false">http://www.emadibrahim.com/?p=383</guid>
		<description><![CDATA[I am working on an asp.net mvc application and I wanted to make the user&#8217;s main page (profile) be www.domain.com/username.&#160; This is a problem because the routing engine in MVC treats the first item after the domain as a controller.&#160; Ofcourse I could do a {*catchall} and do my own parsing but why re-invent the [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on an asp.net mvc application and I wanted to make the user&#8217;s main page (profile) be www.domain.com/username.&nbsp; This is a problem because the routing engine in MVC treats the first item after the domain as a controller.&nbsp; Ofcourse I could do a {*catchall} and do my own parsing but why re-invent the wheel &#8211; plus I suck at regular expression.&nbsp; What I ended up doing is registering all the routes manually.&nbsp; So if I wanted to go to /message/create, I would register a route like this:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.84%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 202px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">routes.Add(
    <span style="color: #0000ff">new</span> Route(<span style="color: #006080">"Message/Create"</span>, <span style="color: #0000ff">new</span> MvcRouteHandler())
        {
            Defaults = <span style="color: #0000ff">new</span> RouteValueDictionary(<span style="color: #0000ff">new</span>
                                                    {
                                                        controller = <span style="color: #006080">"Message"</span>,
                                                        action = <span style="color: #006080">"Create"</span>
                                                    })
        }
    );</pre>
</div>
<p>So far so good, nothing earth shattering.&nbsp; So I basically did this for all my routes and the last route, I added was:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 128px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">routes.Add(
    <span style="color: #0000ff">new</span> Route(<span style="color: #006080">"{*username}"</span>, <span style="color: #0000ff">new</span> MvcRouteHandler())
       {
           Constraints = <span style="color: #0000ff">new</span> RouteValueDictionary(<span style="color: #0000ff">new</span> {username = <span style="color: #006080">"^(?!content/).*"</span>}),
           Defaults = <span style="color: #0000ff">new</span> RouteValueDictionary(<span style="color: #0000ff">new</span> {Controller = <span style="color: #006080">"User"</span>, action = <span style="color: #006080">"View"</span>})
       });</pre>
</div>
<p>This basically will catch any route that has not been defined before it and will treat it as a username so /eibrahim would go to the view action on the user&#8217;s controller.&nbsp; Also, note that I added a constraint to prevent the catch-all route from catching any url in the content subfolder.&nbsp; Important: All your scripts, images, css files and so on have to be in the content folder otherwise they will be handled by the catch-all route and not be accessible to your application.</p>
<p>The signature for the view action look like this:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 95px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> View(<span style="color: #0000ff">string</span> username, <span style="color: #0000ff">int</span>? page)
{

}</pre>
</div>
<p>Now the tricky part is that you want to make sure that your users don&#8217;t signup with a username matching the controller.&nbsp; So if a user decided to register with the username &#8220;message&#8221;, he will never be able to go to his profile at /message because it will be handled by the generic message route &#8220;message/{action}&#8221;.&nbsp; A quick workaround is to prevent the user from registering with those names.&nbsp; In my signup process I call a method to check if the selected username is valid.&nbsp; The validation process loops through all the routes and makes sure the username doesn&#8217;t match any controller or action.&nbsp; It works out pretty well so far.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 142px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">foreach</span> (Route route <span style="color: #0000ff">in</span> RouteTable.Routes)
{
    <span style="color: #0000ff">if</span> (username == route.Defaults[<span style="color: #006080">"controller"</span>].ToString().ToLower())
        <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;
    <span style="color: #0000ff">if</span> (username == route.Defaults[<span style="color: #006080">"action"</span>].ToString().ToLower())
        <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;
}</pre>
</div>
<p>I don&#8217;t know if this is the best solution, so if you know of a better way to do it, let me know.</p>
<div class="aizattos_related_posts"><span class="aizattos_related_posts_header" >Related Posts</span><ul><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/01/05/resolving-url-in-aspnet-using-tilda/" rel="bookmark" title="Permanent Link: Resolving URL in ASP.net using Tilda (~)" >Resolving URL in ASP.net using Tilda (~)</a></span><div class="aizattos_related_posts_excerpt">I have been using .net since it has come out and I just found this out (so, I am kind of pissed).  W...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/01/11/aspnet-20-error-title-is-not-a-member-of-asp%e2%80%a6/" rel="bookmark" title="Permanent Link: asp.net 2.0 Error: &#8216;Title&#8217; is not a member of &#8216;ASP…" >asp.net 2.0 Error: &#8216;Title&#8217; is not a member of &#8216;ASP…</a></span><div class="aizattos_related_posts_excerpt">I had this error come up on a few pages after I deployed my website and it was driving me crazy.  Af...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/03/31/ajax-with-aspnet-mvc-framework-preview-2/" rel="bookmark" title="Permanent Link: Ajax with ASP.NET MVC Framework Preview 2" >Ajax with ASP.NET MVC Framework Preview 2</a></span><div class="aizattos_related_posts_excerpt">This is the updated version of the Nikhil's excellent example on how to use Ajax with ASP.net MVC.
...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/09/07/deciding-between-aspnet-mvc-and-webforms/" rel="bookmark" title="Permanent Link: Deciding Between ASP.NET MVC and WebForms" >Deciding Between ASP.NET MVC and WebForms</a></span></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/08/04/aspnet-ajax-rendering-a-gmail-like-loading-indicator/" rel="bookmark" title="Permanent Link: ASP.NET AJAX: Rendering a Gmail-like &#8216;Loading&#8217; Indicator" >ASP.NET AJAX: Rendering a Gmail-like &#8216;Loading&#8217; Indicator</a></span></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emadibrahim.com/2008/04/10/tricky-aspnet-mvc-url-rewriting/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Unit Test Linq to Sql in ASP.Net MVC with Moq</title>
		<link>http://www.emadibrahim.com/2008/04/04/unit-test-linq-to-sql-in-aspnet-mvc-with-moq/</link>
		<comments>http://www.emadibrahim.com/2008/04/04/unit-test-linq-to-sql-in-aspnet-mvc-with-moq/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 20:29:34 +0000</pubDate>
		<dc:creator>Emad Ibrahim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[mocking]]></category>
		<category><![CDATA[moq]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.emadibrahim.com/2008/04/04/unit-test-linq-to-sql-in-aspnet-mvc-with-moq/</guid>
		<description><![CDATA[I have just spent the entire day playing with Moq to unit test an asp.net mvc application I am working with. All I wanted to do is test a &#8220;create&#8221; method that simply adds a record to the database. So here it goes. 1. I created a Mock Http context to be used by my [...]]]></description>
			<content:encoded><![CDATA[<p>I have just spent the entire day playing with Moq to unit test an asp.net mvc application I am working with. All I wanted to do is test a &#8220;create&#8221; method that simply adds a record to the database. So here it goes.</p>
<p>1. I created a Mock Http context to be used by my controller. I modified the Moq version of the MvcMockHelpers class from <a href="http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx" target="_blank">Scott Hanselman</a> and added two more methods to mock an authenticated user</p>
<blockquote><pre class="code"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #2b91af">HttpContextBase</span> FakeAuthenticatedHttpContext()
{
<span style="color: #0000ff">var</span> context = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">HttpContextBase</span>&gt;();
<span style="color: #0000ff">var</span> request = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">HttpRequestBase</span>&gt;();
<span style="color: #0000ff">var</span> response = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">HttpResponseBase</span>&gt;();
<span style="color: #0000ff">var</span> session = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">HttpSessionStateBase</span>&gt;();
<span style="color: #0000ff">var</span> server = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">HttpServerUtilityBase</span>&gt;();
<span style="color: #0000ff">var</span> user = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">IPrincipal</span>&gt;();
<span style="color: #0000ff">var</span> identity = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">IIdentity</span>&gt;();

context.Expect(ctx =&gt; ctx.Request).Returns(request.Object);
context.Expect(ctx =&gt; ctx.Response).Returns(response.Object);
context.Expect(ctx =&gt; ctx.Session).Returns(session.Object);
context.Expect(ctx =&gt; ctx.Server).Returns(server.Object);
context.Expect(ctx =&gt; ctx.User).Returns(user.Object);
user.Expect(ctx =&gt; ctx.Identity).Returns(identity.Object);
identity.Expect(id =&gt; id.IsAuthenticated).Returns(<span style="color: #0000ff">true</span>);
identity.Expect(id =&gt; id.Name).Returns(<span style="color: #a31515">"test"</span>); <span style="color: #008000">
</span>    <span style="color: #0000ff">return</span> context.Object;
}</pre>
</blockquote>
<blockquote><pre class="code"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span>
SetFakeAuthenticatedControllerContext(<span style="color: #0000ff">this</span> <span style="color: #2b91af">Controller</span> controller)
{
<span style="color: #0000ff">var</span> httpContext = FakeAuthenticatedHttpContext();
<span style="color: #2b91af">ControllerContext</span> context =                  <span style="color: #0000ff">
new</span> <span style="color: #2b91af">ControllerContext</span>(
<span style="color: #0000ff">new</span> <span style="color: #2b91af">RequestContext</span>(httpContext,
<span style="color: #0000ff">new</span> <span style="color: #2b91af">RouteData</span>()), controller);
controller.ControllerContext = context;
}</pre>
</blockquote>
<p>Note that the identity.Name returns &#8220;test&#8221; which is the username of an existing user in the database. If I don&#8217;t do that then the MembershipProvider.GetUser method will fail.</p>
<p>2. I added a couple of properties to my test class (MessageControllerTest) to make it easy for me to access the controller and view engine in all the test methods</p>
<blockquote><pre class="code"><span style="color: #0000ff">private</span> <span style="color: #2b91af">FakeViewEngine</span> _fakeViewEngine;
<span style="color: #0000ff">public</span> <span style="color: #2b91af">FakeViewEngine</span> FakeViewEngine
{
<span style="color: #0000ff">get
</span>    {
<span style="color: #0000ff">if</span> (_fakeViewEngine == <span style="color: #0000ff">null</span>)</pre>
<p></p>
<pre class="code">              _fakeViewEngine = <span style="color: #0000ff">new</span> <span style="color: #2b91af">FakeViewEngine</span>();
<span style="color: #0000ff">return</span> _fakeViewEngine;
}
}

<span style="color: #0000ff">private</span> <span style="color: #2b91af">MessageController</span> authenticatedController;
<span style="color: #0000ff">private</span> <span style="color: #2b91af">MessageController</span> AuthenticatedController
{
<span style="color: #0000ff">get
</span>    {
<span style="color: #0000ff">if</span> (authenticatedController == <span style="color: #0000ff">null</span>)
{
authenticatedController = <span style="color: #0000ff">new</span> <span style="color: #2b91af">MessageController</span>();
authenticatedController.ViewEngine = FakeViewEngine;
authenticatedController.SetFakeAuthenticatedControllerContext();
}
<span style="color: #0000ff">return</span> authenticatedController;
}
}</pre>
</blockquote>
<p>3. I created my test method which is going to call a Create method in my MessageController and pass it a string.</p>
<blockquote><pre class="code">[<span style="color: #2b91af">TestMethod</span>]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Create_Message_Test()
{
AuthenticatedController.Create(<span style="color: #a31515">"This is a test message"</span>);

<span style="color: #008000">//verify
</span>    <span style="color: #2b91af">Assert</span>.AreEqual(<span style="color: #a31515">"Json"</span>, FakeViewEngine.ViewContext.ViewName);
<span style="color: #2b91af">Assert</span>.IsInstanceOfType(FakeViewEngine.ViewContext.ViewData,</pre>
<p></p>
<pre class="code">                             <span style="color: #0000ff">typeof</span>(MyViewData));
<span style="color: #2b91af">Assert</span>.IsTrue(((MyViewData)FakeViewEngine.ViewContext</pre>
<p></p>
<pre class="code">                            .ViewData).isSuccessful);
<span style="color: #2b91af">Assert</span>.IsNotNull(((MyViewData)FakeViewEngine</pre>
<p></p>
<pre class="code">                            .ViewContext.ViewData).Id);

<span style="color: #0000ff">using</span> (MyDataContext dc = <span style="color: #0000ff">new</span> MyDataContext())
{
<span style="color: #0000ff">var</span> query =
dc.Messages.Where(
m =&gt; m.MessageId ==
((MyViewData)FakeViewEngine</pre>
<p></p>
<pre class="code">                       .ViewContext.ViewData).Id);
<span style="color: #008000">//verify it was added to the database
</span>        <span style="color: #2b91af">Assert</span>.AreEqual(1, query.Count());

<span style="color: #008000">//delete it
</span>        dc.Messages.DeleteOnSubmit(query.First());
dc.SubmitChanges();

<span style="color: #008000">//verify it was delete
</span>        <span style="color: #2b91af">Assert</span>.AreEqual(0, query.Count());
}
}</pre>
</blockquote>
<p>Note that in the verification block, I verify:</p>
<ol>
<li>The view being rendered
<li>The returned type of the ViewData
<li>Properties on the ViewData </li>
</ol>
<p>Then I clean up the created message by deleting it from the database.</p>
<p><strong>Important:</strong></p>
<p>You must add your connection strings and membership definition in an app.config file in your test project. If you don&#8217;t then the default consrtuctor of your DataContext will fail to run because it looks for the connection string in the config file.</p>
<p>I am still wrapping my head around the concept of mocking, so any tips or advice will be appreciated.</p>
<p>Here are some good resources that I found during my struggle to get this to work.</p>
<h2>ASP.NET MVC Resources</h2>
<ol>
<li><a title="http://dotnetslackers.com/articles/aspnet/ASPNETMVCFrameworkPart2.aspx" href="http://dotnetslackers.com/articles/aspnet/ASPNETMVCFrameworkPart2.aspx">ASP.NET MVC Framework – Part 2: Testing</a>
<li><a href="http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx">ASP.NET MVC Session at Mix08, TDD and MvcMockHelpers</a> </li>
</ol>
<h2>LINQ to SQL Resources</h2>
<ol>
<li><a href="http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!397.entry">Being Ignorant with LINQ to SQL</a> </li>
</ol>
<h2>Testing and Mocking Resources</h2>
<ol>
<li><a href="http://www.hanselman.com/blog/MoqLinqLambdasAndPredicatesAppliedToMockObjects.aspx">Moq: Linq, Lambdas and Predicates applied to Mock Objects</a>
<li><a href="http://code.google.com/p/moq/">Moq</a>
<li><a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a>
<li><a href="http://weblogs.asp.net/stephenwalther/archive/2008/03/19/tdd-test-driven-development-with-visual-studio-2008-unit-tests.aspx">TDD: Test-Driven Development with Visual Studio 2008 Unit Tests</a> </li>
</ol>
<div class="aizattos_related_posts"><span class="aizattos_related_posts_header" >Related Posts</span><ul><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/04/13/cmap-code-camp-2008-spring-edition/" rel="bookmark" title="Permanent Link: CMAP Code Camp 2008 Spring Edition" >CMAP Code Camp 2008 Spring Edition</a></span><div class="aizattos_related_posts_excerpt">Yesterday, I gave a talk at CMAP Code Camp about the asp.net mvc framework and AJAX using JQuery.  T...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/02/19/improve-linq-query-performance/" rel="bookmark" title="Permanent Link: Improve LINQ Query Performance" >Improve LINQ Query Performance</a></span><div class="aizattos_related_posts_excerpt">I was writing a small utility for Outlook 2007 and was using LINQ to query Outlook Tasks.&#160; This...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/03/31/ajax-with-aspnet-mvc-framework-preview-2/" rel="bookmark" title="Permanent Link: Ajax with ASP.NET MVC Framework Preview 2" >Ajax with ASP.NET MVC Framework Preview 2</a></span><div class="aizattos_related_posts_excerpt">This is the updated version of the Nikhil's excellent example on how to use Ajax with ASP.net MVC.
...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/08/27/mocking-and-dependency-injection-in-aspnet-mvc/" rel="bookmark" title="Permanent Link: Mocking and Dependency Injection in ASP.NET MVC" >Mocking and Dependency Injection in ASP.NET MVC</a></span></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2009/08/18/asp-net-mvc-tdd-free-book-chapter/" rel="bookmark" title="Permanent Link: ASP.NET MVC &amp; TDD Free Book Chapter" >ASP.NET MVC &amp; TDD Free Book Chapter</a></span></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emadibrahim.com/2008/04/04/unit-test-linq-to-sql-in-aspnet-mvc-with-moq/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Ajax with ASP.NET MVC Framework Preview 2</title>
		<link>http://www.emadibrahim.com/2008/03/31/ajax-with-aspnet-mvc-framework-preview-2/</link>
		<comments>http://www.emadibrahim.com/2008/03/31/ajax-with-aspnet-mvc-framework-preview-2/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 13:27:25 +0000</pubDate>
		<dc:creator>Emad Ibrahim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.emadibrahim.com/?p=379</guid>
		<description><![CDATA[This is the updated version of the Nikhil&#8217;s excellent example on how to use Ajax with ASP.net MVC. I commented all the changes made in the code and prefixed them with //emad. So just search for //emad and you will see all the changes I made&#8230; Here is a quick list of the changes I [...]]]></description>
			<content:encoded><![CDATA[<p>This is the updated version of the Nikhil&#8217;s excellent <a href="http://www.nikhilk.net/Ajax-MVC.aspx" target="_blank">example</a> on how to use Ajax with ASP.net MVC.</p>
<p>I commented all the changes made in the code and prefixed them with //emad.  So just search for //emad and you will see all the changes I made&#8230;  Here is a quick list of the changes I made to make this compile and run on MVC Preview 2:</p>
<ol>
<li>Removed the [ControllerAction] tags &#8211; they are no longer needed.</li>
<li>Updated the Route Table creation in the global.asax.cs file to work with the new format</li>
<li>Updated the Ajax framework project to use the new classes
<ol>
<li>HttpContextBase instead of IHttpContext</li>
<li>HttpRequestBased instead of IHttpRequest</li>
<li>HttpResponseBase instead of IHttpResponse</li>
</ol>
</li>
<li>Updated the AjaxViewContext constructor to match ViewContext constructor</li>
<li>Changed the web.config to work with the new version (copied and pasted from another preview 2 project)</li>
</ol>
<p>Note: Test project was not updated and will not compile &#8211; sorry, I didn&#8217;t have time to do it.</p>
<p>Here is the updated code: <a href="http://www.emadibrahim.com/wp-content/uploads/2008/03/tasklist.zip">tasklist.zip</a></p>
<div class="aizattos_related_posts"><span class="aizattos_related_posts_header" >Related Posts</span><ul><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2007/06/10/featured-on-aspnet/" rel="bookmark" title="Permanent Link: Featured on ASP.NET" >Featured on ASP.NET</a></span><div class="aizattos_related_posts_excerpt">One of my sites (www.kbshortcuts.com) is featured on Microsoft's AJAX Showcase at http://ajax.asp.ne...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/05/30/upgrading-yonkly-to-aspnet-mvc-preview-3/" rel="bookmark" title="Permanent Link: Upgrading Yonkly to ASP.NET MVC Preview 3" >Upgrading Yonkly to ASP.NET MVC Preview 3</a></span><div class="aizattos_related_posts_excerpt">I just spent this morning upgrading the Yonkly code to work with the newly released ASP.NET MVC Fram...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/04/11/yonkly-open-source-twitter/" rel="bookmark" title="Permanent Link: Yonkly &#8211; Open Source Twitter" >Yonkly &#8211; Open Source Twitter</a></span><div class="aizattos_related_posts_excerpt">[update: Yonkly source code is now public]

[update 2: I just created www.isweat.com using the yon...</div></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/08/10/the-best-javascript-library/" rel="bookmark" title="Permanent Link: The Best JavaScript Library" >The Best JavaScript Library</a></span></li><li><span class="aizattos_related_posts_title"><a href="http://www.emadibrahim.com/2008/04/13/cmap-code-camp-2008-spring-edition/" rel="bookmark" title="Permanent Link: CMAP Code Camp 2008 Spring Edition" >CMAP Code Camp 2008 Spring Edition</a></span></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emadibrahim.com/2008/03/31/ajax-with-aspnet-mvc-framework-preview-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->