Route to a single controller actionhttp://forums.asp.net/t/1476922.aspx/1?Route+to+a+single+controller+actionThu, 01 Oct 2009 20:41:09 -040014769223436174http://forums.asp.net/p/1476922/3436174.aspx/1?Route+to+a+single+controller+actionRoute to a single controller action <p>How do I create a rule for all URLs to a specific View folder to go to the same controller action ... ?&nbsp;</p> <p>For example any URL that ends in ~/Sections/ should go to ~/Sections/Index.</p> <p>I've tried the following to no avail:-</p> <p></p> <p>&nbsp;routes.MapRoute(</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;Sections&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Route name</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;Sections/*&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // URL with parameters</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new { controller = &quot;Sections&quot;, action = &quot;Index&quot;} &nbsp;// Parameter defaults</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</p> <p></p> <p></p> &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;routes.MapRoute(&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;Sections&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Route name&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;Sections/*&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // URL with parameters&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new { controller = &quot;Sections&quot;, action = &quot;Index&quot;} &nbsp;// Parameter defaults&lt;/div&gt; &lt;div style=&quot;position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;&quot; id=&quot;_mcePaste&quot;&gt;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);&lt;/div&gt; <p><br> </p> <p></p> 2009-10-01T18:28:59-04:003436237http://forums.asp.net/p/1476922/3436237.aspx/1?Re+Route+to+a+single+controller+actionRe: Route to a single controller action <p>http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx</p> <p><br> </p> 2009-10-01T19:11:50-04:003436247http://forums.asp.net/p/1476922/3436247.aspx/1?Re+Route+to+a+single+controller+actionRe: Route to a single controller action <p>Resources:</p> <p>You will likely find these resources useful for routing issues: </p> <p>Routes are processed top down, first match is route used.&nbsp; You'll probably need the ability&nbsp;to debug your routes:</p> <p>The first rule that fits the URL is the one that gets used.&nbsp; Default rules should be last.</p> <p>The most general default rule should be the very last.</p> <p>There's a really interesting tool and video that you might want to check out:</p> <p>the <b>RouteDebug dll</b> tool is discussed&nbsp;in the last twenty minutes*<br> of Phil Haack's video:&nbsp; <a href="http://videos.visitmix.com/MIX09/T44F"><font color="#5403fa">http://videos.visitmix.com/MIX09/T44F</font></a>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;<b><i>Ninja on Fire Black Belt Tips</i></b>&quot;.&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Watch the entire video, it's worth your time.&nbsp;</p> <p>ASP.NET MVC documentation is at MSDN:&nbsp;&nbsp;&nbsp;<a href="http://msdn.microsoft.com/en-us/library/dd566232.aspx"><font color="#5403fa"><b>Reference</b></font></a> .</p> <p>Routing is here:<br> <a href="http://msdn.microsoft.com/en-us/library/system.web.routing.aspx">http://msdn.microsoft.com/en-us/library/system.web.routing.aspx</a><br> <a href="http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.aspx">http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.aspx</a><br> <br> see also:&nbsp; <a href="http://weblogs.asp.net/rashid/archive/2009/04/03/asp-net-mvc-best-practices-part-2.aspx"> http://weblogs.asp.net/rashid/archive/2009/04/03/asp-net-mvc-best-practices-part-2.aspx</a><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://www.asp.net/learn/mvc/tutorial-23-cs.aspx">http://www.asp.net/learn/mvc/tutorial-23-cs.aspx</a></p> <p>for IgnoreRoute see:<br> <a href="http://msdn.microsoft.com/en-us/library/dd505203.aspx">http://msdn.microsoft.com/en-us/library/dd505203.aspx</a>&nbsp;in<br> <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.routecollectionextensions.aspx">http://msdn.microsoft.com/en-us/library/system.web.mvc.routecollectionextensions.aspx</a>.</p> 2009-10-01T19:16:21-04:003436361http://forums.asp.net/p/1476922/3436361.aspx/1?Re+Route+to+a+single+controller+actionRe: Route to a single controller action <p>&nbsp;You just need to use a parameter name with your catch-all:</p> &lt;div style=&quot;BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; BACKGROUND-COLOR: #d3d3bd; FONT-FAMILY: monospace; FONT-SIZE: 8pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid&quot; mce_style=&quot;font-family:monospace;font-size: 8pt;border:solid 1pt black; background-color: #d3d3bd;&quot;&gt;routes.MapRoute(<br> <span style="color:#a31515">&nbsp; &quot;Sections&quot;</span><span style="color:black">,<br> </span><span style="color:#a31515">&nbsp; &quot;Sections/{*path}&quot;</span><span style="color:black">,<br> </span><span style="color:blue">&nbsp;&nbsp; new</span><span style="color:black"> { controller = </span><span style="color:#a31515">&quot;Section&quot;</span><span style="color:black">, action = </span><span style="color:#a31515">&quot;Index&quot;</span><span style="color:black"> });<br> </span>&lt;/div&gt; 2009-10-01T20:28:31-04:003436386http://forums.asp.net/p/1476922/3436386.aspx/1?Re+Route+to+a+single+controller+actionRe: Route to a single controller action <p>Thanks for all who pitched in ... I found exactly what i was looking for here .. <a href="http://stackoverflow.com/questions/1263635/route-all-controller-actions-to-a-single-method-then-display-a-view-according-to"> http://stackoverflow.com/questions/1263635/route-all-controller-actions-to-a-single-method-then-display-a-view-according-to</a></p> 2009-10-01T20:41:09-04:00