In your route you are referencing the controller as PuppyController, you shouldn't include the "Controller" part because that's only relevant to the class name. You want the route name instead which is the name of the controller minus "Controller" so in
your case the route name would be Puppy.
Try changing your route to the following:
routes.MapRoute(
"Puppies",
"Puppies/{number}",
new { controller = "Puppy", action = "Puppies", number = UrlParameter.Optional }
);
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 http://getglimpse.com/
That was an error just in this example I made up, in the real code I did not include the "Controller" part, and was still getting this behavior. Good catch though.
ka11isto
0 Points
3 Posts
Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 10, 2012 09:04 PM|LINK
Let's say I have a simple mvc site with one controller.
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:
routes.MapRoute(
"Puppies",
"Puppies/{number}",
new { controller = "PuppyController", action = "Puppies", number = UrlParameter.Optional }
);
...
//default route below
So the url is www.mywebsite.com/Puppies.
Let's say I want to have a link back to this puppies page from another page on the website, like so:
@Html.ActionLink("Click here to see puppies!", "Puppies")
Locally, using the built-in VS debugger, this works just fine.
On windows 2008 server with IIS 7, the link always takes me to:
http://www.mywebsite.com/PuppiesController/Puppies
and throws a 404.
Meanwhile, entering http://mywebsite.com/Puppies as the url on the server will bring up the page fine.
Any and all suggestions are welcome.
Thanks in advance.
Controller Routing 404 mvc3
ignatandrei
All-Star
134527 Points
21579 Posts
Moderator
MVP
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 10, 2012 09:53 PM|LINK
Never seen this. What version of MVC do you have?
ka11isto
0 Points
3 Posts
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 10, 2012 09:58 PM|LINK
Thanks ignatandrei. We're using MVC 3 :/
ignatandrei
All-Star
134527 Points
21579 Posts
Moderator
MVP
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 10, 2012 10:26 PM|LINK
Strange. You have latest version of all.
Is your site public on internet ( it will be easiear to test)?
What's the URL of the page and what's the precise generated html?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 10, 2012 10:35 PM|LINK
In your route you are referencing the controller as PuppyController, you shouldn't include the "Controller" part because that's only relevant to the class name. You want the route name instead which is the name of the controller minus "Controller" so in your case the route name would be Puppy.
Try changing your route to the following:
routes.MapRoute( "Puppies", "Puppies/{number}", new { controller = "Puppy", action = "Puppies", number = UrlParameter.Optional } );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
http://getglimpse.com/
In addition to glimpse the mvc route debugger really helps
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
Blog | Twitter : @Hattan
ka11isto
0 Points
3 Posts
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 11, 2012 01:11 PM|LINK
Hi CodeHobo,
That was an error just in this example I made up, in the real code I did not include the "Controller" part, and was still getting this behavior. Good catch though.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 11, 2012 04:07 PM|LINK
Hmm ok. Can we see the complete route table and action method?
Blog | Twitter : @Hattan
Young Yang -...
All-Star
21111 Points
1817 Posts
Microsoft
Re: Troubleshooting odd behavior with custom route where Controller name is hidden in url
Apr 17, 2012 08:28 AM|LINK
Hi
You problem seems strange, I guess there are something wrong in your "Puppies" action, could you show it to us?
And have a look at this blog: http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
Hope this helpful
Regards
Young Yang
Feedback to us
Develop and promote your apps in Windows Store