2017-12-23 3 views
1

Ich habe zwei Bereiche in meinem Projekt, Admin und Client.C# ASP.NET MVC Mehrere Sprachen auf Front-und Admin-Bereich

RouteConfig.cs

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

     routes.MapRoute(
      name: "Default", 
      url: "{language}/{controller}/{action}/{id}", 
      defaults: new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new[] { "Testing.Controllers" } 
     ); 
    } 

Aktuelle Ergebnisse:

[✓] localhost 
[✓] localhost/en-us 
[✓] localhost/zh-hk 
[✗] localhost/admin 
[✗] localhost/client 

ich hoffe ich etwas tun kann:

localhost - Home Page (Default Language) 
localhost/en-us - Home Page (English) 
localhost/zh-hk - Home Page (Traditional Chinese) 
localhost/admin/en-us - Admin Area Home Page (English) 
localhost/admin/zh-hk - Admin Area Home Page (Traditional Chinese) 
localhost/client/en-us - Client Area Home Page (English) 
localhost/client/zh-hk - Client Area Home Page (Traditional Chinese) 
+0

haben Sie Route für Gebiet registrieren? – programtreasures

Antwort

1

Sie müssen Bereiche registrieren, bevor allgemeine Route Register

In AreaRegistration.RegisterAllAreas(); vor Ihrem generischen Weg,

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

    AreaRegistration.RegisterAllAreas(); 

    routes.MapRoute(
     name: "Default", 
     url: "{language}/{controller}/{action}/{id}", 
     defaults: new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional }, 
     namespaces: new[] { "Testing.Controllers" } 
    ); 
} 

Ihre Admin-Bereich Registrierung

public class AdminAreaRegistration : AreaRegistration 
{ 
    public override string AreaName 
    { 
     get 
     { 
      return "Admin"; 
     } 
    } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      "Admin_default", 
      "Admin/{language}/{controller}/{action}/{id}", 
      new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
} 

Kundenbereich Registrierung,

public class ClientAreaRegistration : AreaRegistration 
{ 
    public override string AreaName 
    { 
     get 
     { 
      return "Client"; 
     } 
    } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      "Client_default", 
      "Client/{language}/{controller}/{action}/{id}", 
      new { language = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
}