0

我正在尝试一些自定义路由,但是当我尝试访问我的网站时,我得到了 404。

我已经在我的 global.asax 中尝试了这两种方法

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapRoute(
        name: "Show",
        url: "{controller}/{action}/{trip}/{year}/{user}",
        defaults :new  { controller = "Home", action = "Show" }
        );
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapRoute(
        "Default",
        "{controller}/{action}/{trip}/{year}/{user}",
        new { controller = "Home", action = "Show", trip = "", year = "", user = "" }
        );
}

这是控制器操作方法:

public ActionResult Show(string trip, string year, string user)
{
    ViewBag.imagepath = "/Uploadedimages/" + trip + "/" + year + "/" + user + "/";
    return View();
}

这是我如何尝试点击它的示例 URL:

http://localhost:31065/home/show/green/2013/hunt

我的 global.asax 中的这些方法都不起作用。我读过的所有内容都会让我相信这应该有效。

我在这里想念什么?

4

1 回答 1

0

这是我RouteConfig的与 URL 一起使用的http://localhost:31065/home/show/green/2013/hunt

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

        routes.MapRoute(
            name: "Show",
            url: "{controller}/{action}/{trip}/{year}/{user}",
            defaults: new { controller = "Home", action = "Show" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}
于 2013-08-22T23:42:29.340 回答