c#mvc3加载不同的视图

时间:2012-06-06 15:59:29

标签: c# asp.net-mvc-3

我正在检查用户是否经过身份验证,如果用户未经过身份验证,则需要指向其他视图。

public ActionResult UserMaintenance()
{

  if (User.Identity.IsAuthenticated)
  {
    return View();
  }
  else
  {
    LogOn.View;   //// this is the area that needs help
  }
}

我想向用户显示输入登录名和密码的视图....

谢谢

2 个答案:

答案 0 :(得分:2)

您可以将RedirectToAction用于任何控制器中的任何操作。

return RedirectToAction("Action", "Controller");

当您使用ASP.net MVC时,可以将其重定向到LogOn控制器中的Account操作

public ActionResult UserMaintenance()
{

  if (User.Identity.IsAuthenticated)
  {
    return View();
  }
  else
  {
    return RedirectToAction("LogOn", "Account");   
  }
}

答案 1 :(得分:0)

我会用

http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction(v=vs.98).aspx

并创建一个新的控制器方法来处理登录。

相关问题