Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#ASP.NET MVC前端和管理区域的多种语言_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

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 }
        );
    }
}

你们登记了这个地区的路线了吗?