user3534239 user3534239 - 3 months ago 7
ASP.NET (C#) Question

Can't RedirectToAction("RedirectToDefault") in MVC 5

I'm following this tutorial using MVC 5. But I cannot return

RedirectToAction("RedirectToDefault")
; it just stays at form login, and whether true or false password not happened

public ActionResult RedirectToDefault()
{
String[] roles = Roles.GetRolesForUser();

if (roles.Contains("Administrator"))
{
return RedirectToAction("Index", "Admin");
}
else if (roles.Contains("Dealer"))
{
return RedirectToAction("Index", "Dealer");
}
else if (roles.Contains("PublicUser"))
{
return RedirectToAction("Index", "PublicUser");
}
else
{
return RedirectToAction("Index");
}
}


in MyRoleProvider class

public override string[] GetRolesForUser(string username)
{
using (RoleAccessEntities objContext = new RoleAccessEntities())
{
var objUser = objContext.Users.FirstOrDefault(x => x.AppUserName == username);
if (objUser == null)
{
return null;
}
else
{
string[] ret = objContext.Roles.Select(x => x.RoleName).ToArray();
return ret;
}
}
}

Answer

I try return Redirect("/Home/RedirectToDefault"); and it works fine.

use full address "/controller/action" in redirect.

Comments