Troubleshooting odd behavior with custom route where Controller name is hidden in urlhttp://forums.asp.net/t/1791373.aspx/1?Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlTue, 17 Apr 2012 08:28:21 -040017913734925751http://forums.asp.net/p/1791373/4925751.aspx/1?Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlTroubleshooting odd behavior with custom route where Controller name is hidden in url <p>Let's say I have a simple mvc site with one controller.</p> <p>Let's say I have a route in global.asax where I do not want the controller name to be shown in the url, like so:</p> <p>routes.MapRoute(<br> &quot;Puppies&quot;,<br> &quot;Puppies/{number}&quot;,<br> new { controller = &quot;PuppyController&quot;, action = &quot;Puppies&quot;, number = UrlParameter.Optional }<br> );</p> <p>...</p> <p>//default route below</p> <p>So the url is www.mywebsite.com/Puppies.</p> <p>Let's say I want to have a link back to this puppies page from another page on the website, like so:</p> <p>@Html.ActionLink(&quot;Click here to see puppies!&quot;, &quot;Puppies&quot;)</p> <p>Locally, using the built-in VS debugger, this works just fine.</p> <p>On windows 2008 server with IIS 7, the link always takes me to:</p> <p>http://www.mywebsite.com/PuppiesController/Puppies</p> <p>and throws a 404.</p> <p>Meanwhile, entering http://mywebsite.com/Puppies as the url on the server will bring up the page fine.</p> <p></p> <p>Any and all suggestions are welcome.</p> <p>Thanks in advance.</p> 2012-04-10T21:04:32-04:004925796http://forums.asp.net/p/1791373/4925796.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p></p> <blockquote><span class="icon-blockquote"></span> <h4>ka11isto</h4> <p></p> <p>On windows 2008 server with IIS 7, the link always takes me to:</p> <p>http://www.mywebsite.com/PuppiesController/Puppies</p> <p></p> </blockquote> <p></p> <p>Never seen this. What version of MVC do you have?</p> <p></p> 2012-04-10T21:53:06-04:004925800http://forums.asp.net/p/1791373/4925800.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p>Thanks ignatandrei. We're using MVC 3 :/</p> 2012-04-10T21:58:44-04:004925818http://forums.asp.net/p/1791373/4925818.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p>Strange. You have latest version of all.&nbsp;</p> <p>Is your site public on internet ( it will be easiear to test)?</p> <p>What's the URL of the page and what's the precise generated html?</p> <p></p> 2012-04-10T22:26:49-04:004925820http://forums.asp.net/p/1791373/4925820.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p>In your route you are referencing the controller as PuppyController, you shouldn't include the &quot;Controller&quot; part because that's only relevant to the class name. You want the route name instead which is the name of the controller minus &quot;Controller&quot; so in your case the route name would be Puppy.&nbsp;</p> <p>Try changing your route to the following:</p> <pre class="prettyprint">routes.MapRoute( &quot;Puppies&quot;, &quot;Puppies/{number}&quot;, new { controller = &quot;Puppy&quot;, action = &quot;Puppies&quot;, number = UrlParameter.Optional } );</pre> <p>Edit: Also, install glimpse and enable it on the server, that way you can see what routes are being hit and it will help you debug the issue<br> <a href="http://getglimpse.com/">http://getglimpse.com/</a>&nbsp;</p> <p>In addition to glimpse the mvc route debugger really helps<br> <a href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx">http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx</a>&nbsp;</p> 2012-04-10T22:35:14-04:004927042http://forums.asp.net/p/1791373/4927042.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p>Hi CodeHobo,</p> <p>That was an error just in this example I made up, in the real code I did not include the &quot;Controller&quot; part, and was still getting this behavior. Good catch though.</p> 2012-04-11T13:11:11-04:004927415http://forums.asp.net/p/1791373/4927415.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p>Hmm ok. Can we see the complete route table and action method?</p> 2012-04-11T16:07:49-04:004936194http://forums.asp.net/p/1791373/4936194.aspx/1?Re+Troubleshooting+odd+behavior+with+custom+route+where+Controller+name+is+hidden+in+urlRe: Troubleshooting odd behavior with custom route where Controller name is hidden in url <p>Hi</p> <p>You problem seems strange, I guess there are something wrong in your &quot;Puppies&quot; action, could you show it to us?</p> <p>And have a look at this blog: <a href="http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx"> http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx</a></p> <p>Hope this helpful<br> Regards<br> Young Yang</p> 2012-04-17T08:28:21-04:00