Reputation: 15754
I'm having a terrible time with a routing issue. Hopefully you can help me out.
Here are the URL's that work:
http://www.example.com/Stories/Action-Name/StoryName
http://www.example.com/Stories/Action-Name/
(it automatically redirects to ~/Stories/Action-Name/StoryName which is what I want.
However, if I remove the trailing "/" (i.e http://www.example.com/Stories/Action-Name) then it redirects to: http://www.example.com/StoryName
I have no idea how or why this is happening.
Here's the route I have setup in Global.asax:
routes.MapRoute("SurvivorStoriesRedirect", "Stories/Action-Name/{id}", new {
controller = "Stories",
action = "Action-Name",
id = UrlParameter.Optional
});
Please let me know what I'm doing wrong.
Thanks.
EDIT --
Not sure what or how I was messing this up but I just added this:
routes.MapRoute("SurvivorStoriesRedirect", "Stories/{action}/{id}", new {
controller = "Stories",
action = "Index",
id = UrlParameter.Optional
});
And removed any other routes for the "Stories" controller, and all seemed to work.
Upvotes: 0
Views: 117
Reputation: 13533
Grab Phil Haack's routedebugger from NuGet or download the zip from Phil's post and you'll be able to view the matches which won't show you the why but you'll see the how and soon figure it out.
Upvotes: 1
Reputation: 7834
You might need to create a route to handle default action calls. Try this:
routes.MapRoute("SurvivorStoriesDefault", "Stories/Action-Name", new {
controller = "Stories",
action = "Action-Name"
});
Upvotes: 3