I’m trying to authorize that if you are an admin, you will be redirected to an admin site. If you are a member, it will redirect you to the member site.
Here is my code on the controller:
public ActionResult Index(Login model)
{
if (ModelState.IsValid)
{
if (model.IsUserExist(model.EmailId, model.Password))
{
if (Roles.IsUserInRole("Admin"))
{
ViewBag.UserName = model.EmailId;
FormsAuthentication.RedirectFromLoginPage(model.EmailId, false);
return RedirectToAction("AdminSite", "Home");
}
if (Roles.IsUserInRole("Member"))
{
ViewBag.UserName = model.EmailId;
FormsAuthentication.RedirectFromLoginPage(model.EmailId, false);
return RedirectToAction("MemberSite", "MobileHome");
}
}
else
{
ModelState.AddModelError("", "Wrong Email or Password!");
}
}
return View(model);
}
I don’t know what is wrong, but the site just stays on the login page. It just refreshes when I login as a member or admin. It didn’t take me to the admin site or member site.
To use
method you have to have ReturnURL variable name in the querystring. See the specyfication. So it don’t get to
return RedirectToAction("MemberSite", "Home")orreturn RedirectToAction("AdminSite", "Home"). If you will comment out that method it will redirect you to given action.