I am having problems with redirecting from one controller to another, my ASP.NE MVC application starts on the login page, then moves to an otp page when the user successfully logged in (The LOGIN and OTP actions is in the same controller).
When the OTP was successfully submitted, then the application must continue to the menu page, but instead it redirects back to the login page.
AuthenticateController: Login action
// POST: /Authenticate/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(ViewModel_Login model)
{
// do login validation
if (loggedin)
{
return View("OTPAuthentication");
}
else
{
return View(model);
}
}
AuthenticateController: OTPAuthentication action
// POST: /Authenticate/OTPAuthentication
[HttpPost]
[AuthorizeUser]
[ValidateAntiForgeryToken]
public ActionResult OTPAuthentication(ViewModel_OTP model)
{
if (ModelState.IsValid)
{
// do OTP validation
return this.RedirectToAction("MainMenu", "Options");
}
else
{
ModelState.AddModelError("", "The one time pin provided is incorrect.");
}
return View(model);
}
OptionsController: MainMenu action
// GET: /Options/MainMenu
[AuthorizeUser]
public ActionResult MainMenu()
{
return View();
}
RouteConfig:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Authenticate", action = "Login", id = UrlParameter.Optional });
routes.MapRoute(
name: "Menu",
url: "Menu",
defaults: new { controller = "Options", action = "MainMenu" });
routes.MapRoute(
name: "Login",
url: "Login",
defaults: new { controller = "Authenticate", action = "Login" });
routes.MapRoute(
name: "OTP",
url: "OTP",
defaults: new { controller = "Authenticate", action = "OTPAuthentication" });
MainMenuaction? is it specified?