2

I've got an ASP.NET MVC site under a Classic ASP site. The MVC site is:

http://www.inrix.com/traffic

The routes

http://www.inrix.com/traffic
http://www.inrix.com/traffic/home
http://www.inrix.com/traffic/features

work fine. However, the route:

http://www.inrix.com/traffic/support

does not. Click it to see what I'm getting. If I include the action:

http://www.inrix.com/traffic/support/index

it works.

When I run this at home by pressing F5 in VS, it works fine with just http://www.inrix.com/traffic/support (i.e., no action specified). Here are my routes:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Terms",
        "{controller}/{id}",
        new { controller = "Terms", action = "Index" }
        );

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

    routes.MapRoute(
        "ThankYou",
        "{controller}/{action}/{email}/{id}"
        );
}

www.inrix.com/traffic maps to HomeController (Index action).

I want www.inrix.com/traffic/support to map to SupportController, Index action.

What's going on with the "support" route?

Additional Code:

Controller:

using System.Web.Mvc;

namespace InrixTraffic.Controllers
{
    public class SupportController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }
}

View:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Support</title>
</head>
    <body>
        <h1>Hello!</h1>
    </body>
</html>

New route:

    routes.MapRoute(
        "Support",
        "traffic/support",
        new { controller = "Support", action = "Index" }
        );
0

2 Answers 2

2

@EDIT: I think you have a file path (folder probably) with that same url. I mean, a folder named "support". In order to override file path with route path you need to add:

routes.RouteExistingFiles = true;
Sign up to request clarification or add additional context in comments.

3 Comments

You're correct about F5 running debug at localhost. See the end of the post for clarification of your questions.
@birdus, please check my updated answer and delete previous comments for simplicity on the discussion. Hope that works.
That's it! As it turns out, I didn't really need that directory, so I just deleted it and that fixed it. Thanks!
1

Do you have a Traffic controller with an Index action? If so I think you need to set-up a route like whats shown below:

routes.MapRoute(
    "Terms",
    "traffic/support",
    new { controller = "Traffic", action = "Index" }
    );

Place this route above your Terms route in your RegisterRoutes method.

EDIT

I would setup my routes like this:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Support",
        "traffic/support",
        new { controller = "Support", action = "Index" }
    );

    // don't know why you need the id at the end
    routes.MapRoute(
        "Terms",
        "terms",
        new { controller = "Terms", action = "Index" }
        );

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

    // why does this route not have any defaults defined?
    routes.MapRoute(
        "ThankYou",
        "{controller}/{action}/{email}/{id}"
        );
}

8 Comments

Traffic actually goes to HomeController. SupportController.Index is where I want this URL to go. I clarified that at the bottom of the question.
So you want to add this route instead routes.MapRoute( "Terms", "traffic/support", new { controller = "Support", action = "Index" } );
The reason your traffic/support route is failing to match is because your Default route will look for a TrafficController with a 'Support' Action. You need to put the above route before the Default route in your RegisterRoutes method.
Thanks for your help with the basics on routing. The Id for Terms is because there can be a number of languages and I'm passing in something like "de" for the language (de = German). That's something else I'm having a problem with and haven't gotten an answer for. stackoverflow.com/questions/15688789/…
Looks like I don't even need the Support route. I removed it and the route works just fine. I like simpler. Looks like that uses the Default route.
|

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.