域相关路由 ASP MVC 3

发布于 2024-12-29 16:03:52 字数 758 浏览 2 评论 0原文

我有两个域:

mydomain.com 和 mydomain.fr

它们都对应相同的 IP 地址。

我希望用户输入 mydomain.com 来查看页面 A (Controller = "Application" Action = "A" ) 用户输入 mydomain.fr 来查看页面 B (Controller = "ApplicationFR" Action = "B")

我正在使用 ASP.NET MVC 3 并且默认路由映射到页面 A。

我怎样才能实现这一点?


编辑:

我尝试使用提供的示例,但似乎不起作用。 这是注册自定义路由的正确方法吗?

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.Add(new ExampleRoute());
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Application", action = "B", id = UrlParameter.Optional } // Parameter defaults
    );  
}

I have two domains:

mydomain.com
and
mydomain.fr

They both correspond to the same IP address.

I want users typing mydomain.com to view page A (Controller = "Application" Action = "A" )
and users typing mydomain.fr to view page B (Controller = "ApplicationFR" Action = "B" )

I am using ASP.NET MVC 3 and the default route is mapped to page A.

How can I achieve this ?


EDIT:

I tried to use the example provided but it seems not to work.
Is it the right way to register the custom route ?

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.Add(new ExampleRoute());
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Application", action = "B", id = UrlParameter.Optional } // Parameter defaults
    );  
}

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

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

发布评论

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

评论(1

醉南桥 2025-01-05 16:03:52

您可以通过创建一个新路由并将其添加到 global.asaxRegisterRoutes 中的路由集合来实现此目的。

查看这个问题: 是否可以基于子域创建 ASP.NET MVC 路由?

You can do it by creating a new route and adding it to the routes collection in RegisterRoutes in your global.asax.

Check out this question: Is it possible to make an ASP.NET MVC route based on a subdomain?

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