Request.GetOwinContext().Authentication.SignIn不创建cookie

NSS*_*NSS 11 cookies owin asp.net-identity asp.net-web-api2

以下代码不是创建.ASPNET Cookie,我在WebAPI自定义登录方法中使用此代码

  //TODO Validate Credential
  var claims = new List<Claim>();
            claims.Add(new Claim(ClaimTypes.Name, "ABCDE"));
            claims.Add(new Claim(ClaimTypes.Email, "ABCDE@EFGH.com"));

            var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            var authmgr = Request.GetOwinContext().Authentication;
            authmgr.SignIn(id);
Run Code Online (Sandbox Code Playgroud)

ecc*_*o88 3

您是否确定将以下内容添加到 App_Start/Startup.Auth.cs 中?

public void ConfigureAuth(IAppBuilder app)
{
   app.UseCookieAuthentication(new CookieAuthenticationOptions
   {
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
      LoginPath = new PathString("/Account/Login")
   });
}
Run Code Online (Sandbox Code Playgroud)

看看布洛克·艾伦的入门书 -

http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/