<?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>Schotime.net &#187; Routing</title>
	<atom:link href="http://schotime.net/blog/index.php/tag/routing/feed/" rel="self" type="application/rss+xml" />
	<link>http://schotime.net/blog</link>
	<description>All Things .Net and Me</description>
	<lastBuildDate>Sun, 20 Nov 2011 01:44:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Running ASP.NET MVC Applications Under IIS6</title>
		<link>http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/</link>
		<comments>http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 09:41:29 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Routing]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/</guid>
		<description><![CDATA[Yes&#8230;Finally&#8230;I have full control of my HTML again, but am still able to work with a great language like C#. MVC is here and its great. I&#8217;m absolutely loving it. But how the heck do you get it to work under IIS6. What if I want extensionless URL&#8217;s? Here is a few options for you. [...]]]></description>
			<content:encoded><![CDATA[<p>Yes&#8230;Finally&#8230;I have full control of my HTML again, but am still able to work with a great language like C#. MVC is here and its great. I&#8217;m absolutely loving it. But how the heck do you get it to work under IIS6. What if I want extensionless URL&#8217;s? Here is a few options for you.</p>
<p><strong>Option 1:      <br /></strong>Running IIS with Wildcard Application mapping.</p>
<p>This option allows extensionless URL&#8217;s but a what performance price. Every single request including images, files and css etc. will get passed through the aspnet_isapi.dll. For small sites this may not be a huge issue, but small sites soon because large sites and this then becomes an issue.</p>
<p>I&#8217;m not going to run through how to do this, because there are already some nice blogs about this and I don&#8217;t really recommend this option.</p>
<p><strong>Option 2:      <br /></strong>Running IIS with .mvc (or whatever you like) extensions.</p>
<p>I started out running my site (schotime.net) like this, however in the end I decided on Option 3.    <br />URLs look like this.&#160;&#160; /Home.mvc/Index&#160;&#160; rather than /Home/Index&#160; which is not that bad but again not as nice as the latter.</p>
<p>Anyways here&#8217;s how you set this up.    <br />Firstly your global.asax.cs should look like this.</p>
<table style="background: black" cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Collections.Generic;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Linq;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Mvc;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Routing;

</span><span style="background: black; color: #cc7832">namespace </span><span style="background: black; color: white">MVCApplication1
{
    </span><span style="background: black; color: #cc7832">public class </span><span style="background: black; color: #ffc66d">MvcApplication </span><span style="background: black; color: white">: System.Web.HttpApplication
    {
        </span><span style="background: black; color: #cc7832">public static void </span><span style="background: black; color: white">RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(</span><span style="background: black; color: #a5c25c">&quot;{resource}.axd/{*pathInfo}&quot;</span><span style="background: black; color: white">);

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Default&quot;</span><span style="background: black; color: white">,                                              </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #a5c25c">&quot;{controller}.mvc/{action}/{id}&quot;</span><span style="background: black; color: white">,                       </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">}  </span><span style="background: black; color: gray">
            </span><span style="background: black; color: white">);

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Defaultest&quot;</span><span style="background: black; color: white">,                                           </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #a5c25c">&quot;Default.aspx&quot;</span><span style="background: black; color: white">,                                         </span><span style="background: black; color: gray">
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">}  </span><span style="background: black; color: gray">
            </span><span style="background: black; color: white">);

        }

        </span><span style="background: black; color: #cc7832">protected void </span><span style="background: black; color: white">Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            RouteTable.Routes.RouteExistingFiles = </span><span style="background: black; color: #cc7832">true</span><span style="background: black; color: white">;
        }
    }
}</span></pre>
<p>        <a href="http://11011.net/software/vspaste" onclick="pageTracker._trackPageview('/outgoing/11011.net/software/vspaste?referer=');"></a></td>
</tr>
</tbody>
</table>
<p>This will get you started. All you need to do then is map the extension .mvc to the aspnet_isapi.dll in IIS under Home Directory -&gt; Configuration -&gt; Mappings or use an already mapped extension like .aspx and your mvc application should work.</p>
<p><strong>Option 3:<br />
    <br /></strong>This option requires the use of a clever isapi filter to rewrite the URLs. </p>
<p>I originally read an article on <a href="http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/?referer=');">Bia Securities</a> which uses the Isapi_rewrite 3rd party plugin however, Isapi_rewrite is not free so I thought I would find a suitable open source solution. Here it is: Ionic Rewriter -&gt; <a title="http://www.codeplex.com/IIRF" href="http://www.codeplex.com/IIRF" onclick="pageTracker._trackPageview('/outgoing/www.codeplex.com/IIRF?referer=');">http://www.codeplex.com/IIRF</a> </p>
<p>It works in much the same way as the isapi_rewrite but will a few little differences. Once you download the IsapiRewrite4.dll, place the dll in a directory eg. C:\WINDOWS\system32\inetsrv\IIRF and run through the installation instructions included in the download (readme.txt) under Installation. Next comes the configuration. Firstly here is the IsapiRewrite4.ini configuration file ported from the <a href="http://biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/biasecurities.com/blog/2008/how-to-enable-pretty-urls-with-asp-net-mvc-and-iis6/?referer=');">Bia Securities</a> article.</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="400">
<p>#RewriteLog&#160; c:\temp\iirfLog.out<br />
          <br />#RewriteLogLevel 3 </p>
<p>RewriteRule ^/Default\.aspx /Home.mvc [I,L] </p>
<p>RewriteRule ^/$ /Home.mvc [I,L] </p>
<p>RewriteRule ^/([\w]+)$ /$1.mvc [I,L] </p>
<p>RewriteRule ^/(?!Content)([\w]*)/(.*) /$1.mvc/$2 [I,L]</p>
</td>
</tr>
</tbody>
</table>
<p>The [I,L] stands for a case-insensitive match and to stop processing if the current rule is a match.</p>
<p><strong>Important Note:<br />
    <br /></strong>Any physical files that you directly linked to should not be routed. In my MVC folder system I store all of these files under the /Content directory. Wherever you store your files replace the text Content with the folder that your files reside. otherwise images, css etc. will fail to display. </p>
<p>Now all that&#8217;s left to do is to modify the global.asax.cs to support this. </p>
<table style="background: black" cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Collections.Generic;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Linq;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Mvc;
</span><span style="background: black; color: #cc7832">using </span><span style="background: black; color: white">System.Web.Routing;

</span><span style="background: black; color: #cc7832">namespace </span><span style="background: black; color: white">MVCApplication1
{
    </span><span style="background: black; color: #cc7832">public class </span><span style="background: black; color: #ffc66d">MvcApplication </span><span style="background: black; color: white">: System.Web.HttpApplication
    {
        </span><span style="background: black; color: #cc7832">public static void </span><span style="background: black; color: white">RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(</span><span style="background: black; color: #a5c25c">&quot;{resource}.axd/{*pathInfo}&quot;</span><span style="background: black; color: white">);

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Default&quot;</span><span style="background: black; color: white">,                                              </span><span style="background: black; color: gray">// Route name
                </span><span style="background: black; color: #a5c25c">&quot;{controller}/{action}/{id}&quot;</span><span style="background: black; color: white">,                           </span><span style="background: black; color: gray">// URL with parameters
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">}, </span><span style="background: black; color: gray">// Parameter defaults
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a31515">@&quot;[^\.]*&quot; </span><span style="background: black; color: white">}
            );

            routes.MapRoute(
                </span><span style="background: black; color: #a5c25c">&quot;Defaultmvc&quot;</span><span style="background: black; color: white">,                                               </span><span style="background: black; color: gray">// Route name
                </span><span style="background: black; color: #a5c25c">&quot;{controller}.mvc/{action}/{id}&quot;</span><span style="background: black; color: white">,                           </span><span style="background: black; color: gray">// URL with parameters
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a5c25c">&quot;Home&quot;</span><span style="background: black; color: white">, action = </span><span style="background: black; color: #a5c25c">&quot;Index&quot;</span><span style="background: black; color: white">, id = </span><span style="background: black; color: #a5c25c">&quot;&quot; </span><span style="background: black; color: white">},     </span><span style="background: black; color: gray">// Parameter defaults
                </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">{ controller = </span><span style="background: black; color: #a31515">@&quot;[^\.]*&quot; </span><span style="background: black; color: white">}
            );
        }

        </span><span style="background: black; color: #cc7832">protected void </span><span style="background: black; color: white">Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}</span></pre>
</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong>&#160; The line with this on it -&gt; new { controller = @&quot;[^\.]*&quot; }&#160;&#160; is very important. The routes won&#8217;t work without it. </p>
<p>And that&#8217;s it! You&#8217;re done.<br />
  <br />Personally I like the last option but if you have no access to your hosting web server then Option 2 is probably the best.</p>
<p>Schotime</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2008/10/18/running-aspnet-mvc-applications-under-iis6/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

