0

For example, I want to be able to get my login page as by /login and by /en/login route.

 routes.MapRoute(
            name: "LoginLang",
            url: "{lang}/Login",
            defaults: new { lang = "en", controller = "Account", action = "Login" }
            );

But if /en/login gets accepted, route /login is not. It is treatable by an additional route, but still, do you have explanation why /login gets rejected?

1 Answer 1

2

Because your route pattern says the lang (parameter) string should be before the string "Login" in the url.

If you want to support both en/login and login, you should create one more route entry and register it in the route table.

routes.MapRoute(
   name: "DefaultLoginLang",
   url: "Login",
   defaults: new { lang = "en", controller = "Account", action = "Login" }
);

routes.MapRoute(
   name: "LoginLang",
   url: "{lang}/Login",
   defaults: new { lang = "en", controller = "Account", action = "Login" }
);
// Your default route registration goes here

Or you can use attribute routing

[Route("Login")]
[Route("{lang}/Login")]
public ActionResult Login(string lang="en")
{
   //to do : return something
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.