【发布时间】:2016-08-31 14:17:45
【问题描述】:
我正在使用带有 Identity 2.0 的 WebApi 2.0
我在 startup.auth.cs 中定义了 ApplicationCookie 身份验证,如下所示:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
CookieName = "MyAppCookieName"
});
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
我在 AccountController 中有登录操作:
var claims = new List<Claim>();
// create required claims
claims.Add(new Claim(ClaimTypes.NameIdentifier, "harryb"));
claims.Add(new Claim(ClaimTypes.Name, "harryb"));
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties()
{
AllowRefresh = true,
IsPersistent = true,
ExpiresUtc = DateTime.UtcNow.AddDays(7),
}, identity);
return Ok();
到目前为止一切顺利,客户端在登录请求时收到了 cookie。但是当我提出新的要求时,索赔是空的?我不想使用标准登录和表格等。我只想对假登录提出一些要求,并在下一个请求中阅读它。我错过了什么?
【问题讨论】:
标签: c# asp.net-web-api asp.net-identity