重定向到页面时更新MVC链接

时间:2019-01-26 14:23:58

标签: c# asp.net-mvc razor

我有MVC App,我需要在每次操作中动态添加到站点URL语言符号中。

我在RouteConfig中尝试使用Route失败。

链接示例

http://localhost/en/Account/Index

http://localhost/fr/Account/Index

路由

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
          name: "Default",
          url: "{Language}/{controller}/{action}/{id}",
          defaults: new { Language = "en", controller = "Home", action = "Index", id = UrlParameter.Optional },
          namespaces: new[] { "TestWeb.Controllers" }
      );
    }
}

public class Current
{
    public static string Language
    {
        get
        {
            if (Session["Lang"] == null)
                Session["Lang"] = "en";
            return (string)Session["Lang"];
        }
        set
        {
            Session["Lang"] = value;
        }
    }
}

有什么帮助吗?

0 个答案:

没有答案