0

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

1 Answer 1

1

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.

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.