简体   繁体   English

asp.net中的默认路由参数mvc RouteConfig

[英]default route parameters in asp.net mvc RouteConfig

I have RouteConfig 我有RouteConfig

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

        routes.MapRoute(
          name: "EmployerDefault",
          url: "{lang}/employer",
          defaults: new { lang = "ru", controller = "Employer", action = "Index" }
      );
    }
}

and Controller 和控制器

 public class EmployerController : Controller
{
    public ActionResult Index()
    {
        return View("EmployerMaster");
    }
}

When i go to link /employer , i get HTTP 404.0 - Not Found , but when i try to get /ru/employer it's OK. 当我转到链接/ employer时 ,我得到HTTP 404.0-Not Found,但是当我尝试获取/ ru / employer时就可以了。 I want that /employer and /ru/employer links refer to one page. 我希望/ employer和/ ru / employer链接引用一页。 Why it's happens ? 为什么会发生? How can i fix that ? 我该如何解决?

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

        routes.MapRoute(
          name: "EmployerDefault",
          url: "/employer",
          defaults: new { lang = "ru", controller = "Employer", action = "Index" }

        routes.MapRoute(
          name: "EmployerWithLang",
          url: "{lang}/employer",
          defaults: new { lang = "ru", controller = "Employer", action = "Index" }
      );
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM