c# - 如何在调用 IauthenticationManager.SignIn 后立即获取 OWIN cookie 的值?

标签 c# asp.net-mvc cookies asp.net-identity owin

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/

相关文章:

c# - 序列化并添加到 XDocument

c# - Entity Framework 的持续交付和数据库模式变化

javascript - 如何基于 MVC 中的 Controller 隐藏共享布局中的元素

c# - MVC 中的 OnInit 和 Session

c# - 如何在 Web API 授权属性中获取请求 cookie?

c# - 有关通过 Windows Installer 安装应用程序的问题

c# - 如何在 visual studio 构建前/构建后命令行中检测调试/发布?

html - MVC(五)根据另一个填充下拉列表

c# - ASP.NET 在 HTTP 和 HTTPS 上保护 Cookie

java - 跨域cookie和签名小程序