kolesso
kolesso

Reputation: 336

default route parameters in asp.net mvc RouteConfig

I have 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. I want that /employer and /ru/employer links refer to one page. Why it's happens ? How can i fix that ?

Upvotes: 0

Views: 1338

Answers (1)

Paweł Bejger
Paweł Bejger

Reputation: 6366

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

Upvotes: 1

Related Questions