Tag: asp.net membership

成功登录后,User.Identity.IsAuthenticated为false

成功登录后,我需要直接获取UserId Guid。 以下代码不起作用: if (Membership.ValidateUser(txtUsername.Value, txtPassword.Value)) { FormsAuthentication.SignOut(); FormsAuthentication.SetAuthCookie(txtUsername.Value, true); if (HttpContext.Current.User.Identity.IsAuthenticated) { // doesn’t run Guid puk = (Guid)Membership.GetUser().ProviderUserKey; } } 以下代码确实有效: if (Membership.ValidateUser(txtUsername.Value, txtPassword.Value)) { FormsAuthentication.SignOut(); FormsAuthentication.SetAuthCookie(txtUsername.Value, true); MembershipUser user = Membership.GetUser(txtUsername.Value); if (user != null) { Guid puk = (Guid)user.ProviderUserKey; } } 为什么会这样? 除了SetAuthCookie之外还有更多的事情SetAuthCookie吗?