域相关路由 ASP MVC 3
我有两个域:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过创建一个新路由并将其添加到
global.asax
的RegisterRoutes
中的路由集合来实现此目的。查看这个问题: 是否可以基于子域创建 ASP.NET MVC 路由?
You can do it by creating a new route and adding it to the routes collection in
RegisterRoutes
in yourglobal.asax
.Check out this question: Is it possible to make an ASP.NET MVC route based on a subdomain?