0

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.

2
  • In all likelihood it's using another route that you've defined. Commented Feb 3, 2011 at 21:08
  • I moved that route to the top to see if that was occurring and it still happens. Commented Feb 3, 2011 at 21:09

2 Answers 2

3

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"
            });
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.