域名相关路由ASP MVC 3 [英] Domain dependent routing ASP MVC 3

查看:81
本文介绍了域名相关路由ASP MVC 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个域:

mydomain.com

mydomain.fr

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

我希望用户键入mydomain.com查看页面A(控制器=应用程序行动=A)
和用户输入mydomain.fr查看页面B(控制器=ApplicationFR行动=B)

我使用ASP.NET MVC 3,默认路由映射到页面A.

我怎样才能做到这一点?


编辑:

我试图用提供的例子,但它似乎不工作。
它是注册自定义路线的正确方法?

 公共静态无效的RegisterRoutes(RouteCollection路线)
{
    routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);
    routes.Add(新ExampleRoute());
    routes.MapRoute(
        默认,//路线名称
        {控制器} / {行动} / {ID},// URL带参数
        新{控制器=应用程序,行动=B,ID = UrlParameter.Optional} //参数默认
    );
}


解决方案

您可以通过创建一个新的途径,并在的RegisterRoutes 在将它添加到路由集合做你的的Global.asax

看看这个问题:<一href=\"http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain\">Is有可能使基于子域的ASP.NET MVC路线?

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

解决方案

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?

这篇关于域名相关路由ASP MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆