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" }
        );
4

2 回答 2

2

@EDIT:我认为您有一个具有相同网址的文件路径(可能是文件夹)。我的意思是,一个名为“支持”的文件夹。为了用路由路径覆盖文件路径,您需要添加:

routes.RouteExistingFiles = true;
于 2013-04-30T23:49:11.177 回答
1

你有一个带索引动作的流量控制器吗?如果是这样,我认为您需要设置如下所示的路线:

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

将此路由放在 RegisterRoutes 方法中的条款路由上方。

编辑

我会像这样设置我的路线:

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}"
        );
}
于 2013-04-30T21:42:51.303 回答