加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.net – 何时设置HttpContext.User.Identity?

发布时间:2020-12-16 00:42:54 所属栏目:asp.Net 来源:网络整理
导读:我有认证码: var authTicket = new FormsAuthenticationTicket(/*blahblah....*/);var cookie = new HttpCookie(FormsAuthentication.FormsCookieName,FormsAuthentication.Encrypt(authTicket));Response.Cookies.Add(cookie);var name = HttpContext.User
我有认证码:
var authTicket = new FormsAuthenticationTicket(/*blahblah....*/);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName,FormsAuthentication.Encrypt(authTicket));
Response.Cookies.Add(cookie);
var name = HttpContext.User.Identity.Name; // line 4

通过放入调试语句,我发现第4行的名称是空的。但是下次我在这个浏览器会话中打电话时,HttpContext.User.Identity.Name被正确设置。

那么这个值什么时候设置?

解决方法

如果给定的请求包含身份验证cookie,则将设置HttpContext.User.Identity.Name。在你的情况下,cookie刚被添加到浏览器的响应中来。浏览器会在以下请求中添加cookie(如果存在)。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读