2013-05-29 91 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中的註冊路由。它的遺產完成了。 而且你不需要任何區域來實現多文化功能。