ClaimsIdentity ident = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthManager.SignOut();
AuthManager.SignIn(new AuthenticationProperties { IsPersistent = userInfo.rememberMe }, ident);
//I would like to get the value here
所以我尝试使用 HttpContext.Request.Cookies["cookieName"].Value
但它不起作用。事实上,当我执行 HttpContext.Response.Cookies.Count
时,它返回了 0。
最佳答案
身份验证管理器此时未设置 cookie。它仅使用应写入 cookie 的身份对象设置回调。所以 SignIn
方法只在内存中存储值,直到响应被实际发送出去。我做了write about this recently .
无论如何,即使您获得了 cookie 的值,它也是由 OWIN 加密的,更改它的值很可能会使 cookie 失效。
你想用 cookie 做什么?
关于c# - 如何在调用 IauthenticationManager.SignIn 后立即获取 OWIN cookie 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25689248/