2013-05-29 92 views
0

我学习的课程描述了如何使用两种或多种语言创建网站,
和本课的第一步 - 我需要在我的项目中添加以下代码网站上的两种语言asp.net mvc 4

context.MapRoute(
      name: "lang", 
      url: "{lang}/{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      constraints : new { lang = @"ru|en" }, 
      namespaces: new[] { "LessonProject.Areas.Default.Controllers" } 
     ); 

     context.MapRoute(
      name : "default", 
      url : "{controller}/{action}/{id}", 
      defaults : new { controller = "Home", action = "Index", id = UrlParameter.Optional, lang = "ru" }, 
      namespaces : new [] { "LessonProject.Areas.Default.Controllers" } 
     ); 

文件DefaultAreaRegistration (/Areas/Default/DefaultAreaRegistration.cs)
但我没有在我的项目文件。
我不明白我需要创建一个新的文件夹区域和一个新的文件DefaultAreaRegistration.cs或者我需要改变RouteConfig.cs文件,其中包含

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
} 


而在Global.asax中有下面的代码
AreaRegistration.RegisterAllAreas();

什么是我需要改变的部分?

回答

0

如果此区域是之前创建的,则需要将此代码添加到DefaultAreaRegistration.cs中。 这意味着当创建区域时不能自动创建多文化路线。因此,如果您的解决方案中没有任何区域,您只需要RouteConfig.cs中的注册路由。它的遗产完成了。 而且你不需要任何区域来实现多文化功能。