Asp.net mvc 3 如何重定向角色不正确的用户(已登录)以查看页面?
我想将角色不正确的用户发送到另一个页面,但是当我使用:Asp.net mvc 3 如何重定向角色不正确的用户(已登录)以查看页面?,asp.net-mvc-3,membership-provider,http-get,redirecttoaction,Asp.net Mvc 3,Membership Provider,Http Get,Redirecttoaction,我想将角色不正确的用户发送到另一个页面,但是当我使用: return RedirectToAction("Index", "Home"); 我得到一个错误: Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.ViewResult' 这个错误是因为我在http GET而不是http POST中吗 以下是我的代码: public ViewResult Index() {
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
}
如何根据用户在这种情况下的角色重定向用户?将方法更改为返回
ActionResult
,而不是ViewResult
。后者要求您返回View()
,而前者是一种基本类型,允许任何类型的ActionResult对象,例如通过RedirectToAction
和View
返回的对象,将方法更改为返回ActionResult
,而不是ViewResult
。后者要求您返回View()
,而前者是允许任何类型的ActionResult对象的基本类型,例如通过RedirectToAction
和View
返回的对象
public ActionResult Index(){
}
而不是
public ViewResult Index(){
}
而不是
public ViewResult Index(){
}