C#ASP.NET MVC前端和管理区域的多种语言
我的项目中有两个方面,C#ASP.NET MVC前端和管理区域的多种语言,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我的项目中有两个方面,Admin和Client RouteConfig.cs public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{language}/{
Admin
和Client
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" }
);
}
目前的结果:
[✓] localhost
[✓] localhost/en-us
[✓] localhost/zh-hk
[✗] localhost/admin
[✗] localhost/client
我希望我能这样做:
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)
您需要先注册区域,然后再注册通用布线 添加
AreaRegistration.Registeralareas()代码>在常规路线之前
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" }
);
}
您的管理区注册
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 }
);
}
}
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 }
);
}
}
客户区注册
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 }
);
}
}
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 }
);
}
}
你们登记了这个地区的路线了吗?