1

您好,我在 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 中的虚拟目录。有人可以帮我吗?我还尝试按如下方式进行映射:

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

但也没有成功

4

1 回答 1

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
        );

规则优先..

于 2010-03-17T19:36:20.520 回答