asp.net mvc 映射路由

发布于 2024-08-25 03:57:25 字数 1438 浏览 6 评论 0原文

问候, 我在 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
    );

但也没有成功

Greetings,
I have a problem with link in mvc application. When I run it via Visual Studio it's ok. The link then is as follows:
http://localhost:2566/ActivateClient/Activate/6543e2d6-707d-44ae-94eb-a75d27ea0d07

when I run it via IIS7 the link is as follows:
http://localhost/ActivationService/ActivateClient/Activate/6543e2d6-707d-44ae-94eb-a75d27ea0d07

The default route is as follows:

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

    }

I assume I have to change this MapRoute, am I right? How to change it? ActivationService is my virtualDirectory in IIS. Can someone help me with this please?
I also tried to maproute as follows:

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

but also without success

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫轩蝶泪 2024-09-01 03:57:25

您是否添加了新的或替换了现有的?

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

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

规则优先..

Did you add the new one or replace the existing one?

If you added, you need to position it before the existing one.

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

The rules take precedence..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文