我AffiliateLogin
在控制器中具有设置Principal
.
该行principal.User = user;
实际上是存储主体的行。但是在我重定向到另一个控制器并测试我的AuthorizeWithRolesAttribute
属性之后,主体被重置。
这是登录后一秒,可以看到红色箭头:
这是存储它的函数。
我究竟做错了什么?
谢谢
public JsonResult AffiliateLogin(string email, string password)
{
if (ModelState.IsValid)
{
Affiliate user = api.GetUserByCredencials<Affiliate>(email, password);
if (user != null)
{
IIdentity identity = new UserIdentity(true,user.Email);
UserPrincipal principal = new UserPrincipal(identity, new string[] {"Affiliate"});
principal.User = user;
HttpContext.User = principal;
return Json("Login success");
}
}
return Json("Fail To Login");
}