我想将角色不正确的用户发送到另一个页面,但是当我使用时:
return RedirectToAction("Index", "Home");
我得到错误:
Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.ViewResult'
这个错误是因为我在 http GET 而不是 http POST 中吗?
这是我的代码:
public ViewResult Index()
{
if (User.IsInRole("Administrator") | User.IsInRole("SuperAdministrator"))
{
//Do Admin Things
return View()
}
else
{
// Send to a different page
return RedirectToAction("Index", "Home"); // I want to do this, but it gives me an error
}
在这种情况下,如何根据用户的角色重定向用户?