<?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>emphess .NET &#187; MVC 2</title>
	<atom:link href="http://www.emphess.net/tag/mvc-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emphess.net</link>
	<description>Christoph Menge&#039;s Blog</description>
	<lastBuildDate>Tue, 15 Jun 2010 00:50:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Areas, Routes and defaults in MVC 2 RC</title>
		<link>http://www.emphess.net/2010/01/31/areas-routes-and-defaults-in-mvc-2-rc/</link>
		<comments>http://www.emphess.net/2010/01/31/areas-routes-and-defaults-in-mvc-2-rc/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 17:36:44 +0000</pubDate>
		<dc:creator>Christoph Menge</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC 2]]></category>
		<category><![CDATA[MVC 2 Areas]]></category>

		<guid isPermaLink="false">http://www.emphess.net/?p=89</guid>
		<description><![CDATA[Download sample
There has been some discussion over at stackoverflow on setting a default route to an area in mvc, so I want to post some very crude, but working example code here&#8230; I will write some explanatory text here if I find the time.
I feel that the fact that the order of operation in Application_Start() [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.emphess.net/wp-content/uploads/2010/01/MvcApplication.zip'>Download sample</a></p>
<p>There has been some discussion over at stackoverflow on <a href="http://stackoverflow.com/questions/2140208/how-to-set-a-default-route-to-an-area-in-mvc/2172438#2172438">setting a default route to an area in mvc</a>, so I want to post some <a href='http://www.emphess.net/wp-content/uploads/2010/01/MvcApplication.zip'>very crude, but working example code here</a>&#8230; I will write some explanatory text here if I find the time.</p>
<p>I feel that the fact that the order of operation in <code>Application_Start()</code> matters is quite problematic, but that has been discussed elsewhere (I&#8217;ll be searching for the link&#8230;) Anyway, when registering the areas first, the default route can be set to an area.</p>
<pre class="brush: csharp">
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
        }
</pre>
<p>In the AreaRegistration, </p>
<pre class="brush: csharp">
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                &quot;ShopArea_default&quot;,
                &quot;{controller}/{action}/{id}&quot;,
                new { action = &quot;Index&quot;, id = &quot;&quot;, controller = &quot;MyRoute&quot; },
                new { controller = &quot;MyRoute&quot; }
            );
        }
</pre>
<p>will do the job. Note the use of the constraint that will only accept requests to the areas&#8217; controller that should be used as a default.</p>
<p>This is a working solution, but I think it is quite error-prone and not very elegant. In the meantime, I started to use <a href="http://www.MvcContrib.org">MvcContrib</a>, because it&#8217;s <a href="http://www.lostechies.com/blogs/hex/archive/2009/11/01/asp-net-mvc-portable-areas-via-mvccontrib.aspx">portable areas are really smart</a>, make deployment easier and foster reusability of the code, <em>and</em> the views.</p>
<div style="float: right;"><p align="right"><a rel="nofollow" class="tt" href="http://twitter.com/home/?status=Areas%2C+Routes+and+defaults+in+MVC+2+RC+http://bit.ly/9Mquem" title="Post to Twitter"><img class="nothumb" src="http://www.emphess.net/wp-content/plugins/tweet-this/icons/tt-twitter2.png" alt="Post to Twitter" /></a> <a rel="nofollow" class="tt" href="http://delicious.com/post?url=http://www.emphess.net/2010/01/31/areas-routes-and-defaults-in-mvc-2-rc/&amp;title=Areas%2C+Routes+and+defaults+in+MVC+2+RC" title="Post to Delicious"><img class="nothumb" src="http://www.emphess.net/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a rel="nofollow" class="tt" href="http://digg.com/submit?url=http://www.emphess.net/2010/01/31/areas-routes-and-defaults-in-mvc-2-rc/&amp;title=Areas%2C+Routes+and+defaults+in+MVC+2+RC" title="Post to Digg"><img class="nothumb" src="http://www.emphess.net/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a rel="nofollow" class="tt" href="http://www.facebook.com/share.php?u=http://www.emphess.net/2010/01/31/areas-routes-and-defaults-in-mvc-2-rc/&amp;t=Areas%2C+Routes+and+defaults+in+MVC+2+RC" title="Post to Facebook"><img class="nothumb" src="http://www.emphess.net/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.emphess.net/2010/01/31/areas-routes-and-defaults-in-mvc-2-rc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
