【发布时间】:2018-08-27 07:51:06
【问题描述】:
我有两个控制器 TokkenIssuer 和 Login。 我已将 [authorize] 用于 TokkenIssuer 中的方法 A,该方法采用登录控制器的视图,然后进入登录控制器的登录操作。
登录控制器:
public ActionResult Login(string user,string password,string returnUrl)
{
FormsAuthentication.SetAuthCookie(user, true);
if (FormsAuthentication.Authenticate(user, password))
{
if (string.IsNullOrEmpty(returnUrl) && Request.UrlReferrer != null)
returnUrl = Server.UrlEncode(Request.UrlReferrer.PathAndQuery);
return RedirectToAction("B", "TokenIssuer");
}
return View();
}
从登录我重定向到令牌发行者控制器中的动作 B。 我开始知道 User.Identity.IsAuthenticated 将在重定向到另一个控制器后变为真,但我无法获取用户对象,也无法在我的重定向控制器 (TokenIssuer) 中找到 User.Identity.IsAuthenticated 为真。
TokenIssuer 控制器
[Authorize]
public ActionResult A() //takes to Login view
{
return View();
}
public ActionResult B() //Redirected from Login controller
{
if(User.Identity.IsAuthenticated) // Getting False
{
string user = User.Identity.Name;
}
}
如何解决这个问题?
【问题讨论】:
标签: asp.net-mvc razor asp.net-mvc-5 forms-authentication wif