0

Im building a asp.net mvc 4 app. Im using forms auth. I have set roles to users and Authenticated the controllers for certain roles but im trying to figure out how to redirect a user when he/she logs in I just want the user directed to a certain area? Im thinking its something to do with login action on the account controller. would a switch statement here on the roles and redirect to action on in different cases?

1 Answer 1

2

If you use the default MVC project in Visual Studio, there is already a redirect going on (to the previous page):

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
//[RequireHttps]
public ActionResult Login(LoginModel model, string returnUrl)
{
    if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
    {
        return RedirectToLocal(returnUrl);
    }

    // If we got this far, something failed, redisplay form
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    return View(model);
}

If you want it to redirect to your own page, just replace the return RedirectToLocal(returnurl) by return RedirectToAction("Index", "Home"); with Index being your actionname and Home being your controller.

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.