Reputation: 4249
I have ASP.NET MVC application. I want my application to redirect from
example.com/Register
to
example.com/Account/Register
How can I do it with routes? It makes little sense to me to make controller only for this one task
public class RegisterController : Controller
{
public ActionResult Index()
{
return RedirectToAction("Register", "Account");
}
}
Upvotes: 0
Views: 111
Reputation: 32510
You don't need a redirect. You need a custom route
Add this route first (above "Default")
routes.MapRoute(
"Register",
"Register",
new { controller = "Account", action = "Register" }
);
This solution will leave the user on URL example.com/Register
, but instantiate Controller Account, execute ActionResult Register, and return View Account/Register.
Upvotes: 1