0

In ASP.NET MVC route configuration is like below:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

I am using [Route] attribute in Controller:

[Route("login")]
public ActionResult Login()
{
    return View();
}

I can go to the page using both /login and Auth/Login. The second link is clearly from the default route, but I don't want that URL to go to my login page.

How can I do that?

0

1 Answer 1

1

To block a route from being served, you can use IgnoreRoute as long as you place it before the route you want to block:

routes.IgnoreRoute(url: "Auth/Login");

// Register any custom routes here...

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
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.