简体   繁体   English

c#mvc3加载不同的视图

[英]c# mvc3 load a different view

I am checking if a user is authenticated, and need to direct to a different view if the user is not autheticated. 我正在检查用户是否经过身份验证,如果用户未经过身份验证,则需要指向其他视图。

public ActionResult UserMaintenance()
{

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

I would like to present the user the view to enter the login and password.... 我想向用户提供输入登录名和密码的视图....

thank you 谢谢

You can use RedirectToAction to any action in any controller. 您可以将RedirectToAction用于任何控制器中的任何操作。

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

As you are using ASP.net MVC you can redirect it to LogOn action in Account controller 当您使用ASP.net MVC时,您可以将其重定向到Account控制器中的LogOn操作

public ActionResult UserMaintenance()
{

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

I would use 我会用

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

and create a new controller method to handle the login. 并创建一个新的控制器方法来处理登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM