asp.net mvc maproute

时间:2010-03-17 19:30:01

标签: asp.net asp.net-mvc maproute

问候, 我在mvc应用程序中遇到链接问题。当我通过Visual Studio运行它时没关系。该链接如下: http://localhost:2566/ActivateClient/Activate/6543e2d6-707d-44ae-94eb-a75d27ea0d07

当我通过IIS7运行它时,链接如下: http://localhost/ActivationService/ActivateClient/Activate/6543e2d6-707d-44ae-94eb-a75d27ea0d07

默认路线如下:

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

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

我想我必须改变这个MapRoute,对吗?怎么改呢? ActivationService是IIS中的virtualDirectory。请有人帮我这个吗? 我还尝试了maproute如下:

routes.MapRoute(
        "Default",                                              // Route name
        "ActivationService/{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

但也没有成功

1 个答案:

答案 0 :(得分:1)

您是添加新的还是替换现有的?

如果您添加了,则需要将其放在现有位置之前。

routes.MapRoute(
        "Default",                                              // Route name
        "ActivationService/{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

规则优先。

相关问题