在ASP.NET MVC多语种网站 [英] Multi-lingual websites with ASP.NET MVC

查看:75
本文介绍了在ASP.NET MVC多语种网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当建立一个多语种网站(使用ASP.NET Web窗体),我将使用一个HTTP模块来重写这些URL的东西友好(用于人类和放大器;搜索引擎),以结束这样的:

When building a multi-lingual website (with ASP.NET web forms), I'll use an HTTP module to rewrite the URLs to end up with something friendly (for humans & search engines) like:

uk/products/product_category_one/sub_category_one/index.aspx
uk/products/product_category_one/sub_category_one/widget_mk5.aspx
es/productos/categoría_de_producto_una/widget_mk5.aspx

MVC的我(新手)的理解是,URL应该采取的格式

My (newbie) understanding of MVC is that the URL should take the format of

控制器/动作/标识符

所以复制功能上面MVC将结束与类似的网址:

so replicating the functionality above with MVC will end up with URLs similar to:

products/category/123/product_category_one/sub_category_one
products/items/456/widget_mk5

问题..


  • 我可以将控制器段前插入一个国家code到URL?

  • 是否有可能映射'产品'和'PRODUCTOS到同一控制器?

感谢您的帮助。

编辑:
除了下面我帕诺斯的回答中发现的 ASP.NET网站了解更多信息

推荐答案

该网址,几乎可以把你喜欢的任何其他形式。欲了解更多信息,请查看<一个href=\"http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx\">ASP.NET MVC框架(第二部分):URL路由。刚刚启动(因为我不知道这是否是最佳的解决方案),你可以在Global.asax中添加两条新航线:

The URL can take almost any other form you like. For more info, check ASP.NET MVC Framework (Part 2): URL Routing. Just for starting (since I am not sure if it is the optimum solution), you can add two new routes in your global.asax:

        routes.MapRoute(
            "ukRoute",
            "{lang}/Products/{action}/{id}/{subcategory}",
            new { lang = "uk", controller = "Products", action = "Index", id = "", subcategory = "" }
        );
        routes.MapRoute(
            "esRoute",
            "{lang}/Productos/{action}/{id}/{subcategory}",
            new { lang = "es", controller = "Products", action = "Index", id = "", subcategory = "" }
        );

这些途径了解以下URL(和他们都映射到的ActionResult类别(串号,串子类)的方法的ProductsController

uk/Products/Category/1/A
es/Productos/Category/1/A

如果你想在你的意见来创建这样的网址,你可以使用这样的:

If you want to create such URLs in your views you can use something like:

<%= Html.RouteLink("English 1.A", "ukRoute", new { lang = "uk", action = "Category", id = "1", subcategory = "A" })%>
<%= Html.RouteLink("Spanish 1.A", "esRoute", new { lang = "es", action = "Category", id = "1", subcategory = "A" })%>

这篇关于在ASP.NET MVC多语种网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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