Page.User.Identity.IsAuthenticated仍然如此FormsAuthentication.SignOut后() [英] Page.User.Identity.IsAuthenticated still true after FormsAuthentication.SignOut()

查看:250
本文介绍了Page.User.Identity.IsAuthenticated仍然如此FormsAuthentication.SignOut后()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,当你preSS'注销',它会重定向到的login.aspx 网​​页,其中有一个的Page_Load 方法,它调用 FormsAuthentication.SignOut()

I have a page that when you press 'log out' it will redirect to the login.aspx page which has a Page_Load method which calls FormsAuthentication.SignOut().

母版页会显示在屏幕的右上角的注销链接并显示其在该 Page.User.Identity.IsAuthenticated 是条件真正。然而,通过code步进后,该signout方法不会自动设置 IsAuthenticated 这是相当恼人的,任何想法?

The master page displays the 'log out' link in the top right of the screen and it displays it on the condition that Page.User.Identity.IsAuthenticated is true. After stepping through the code however, this signout method doesn't automatically set IsAuthenticated to false which is quite annoying, any ideas?

推荐答案

Page.User.Identity.IsAuthenticated Page.User获取其值(明显),这是不幸的是只读的,当你调用不更新 FormsAuthentication.SignOut()

Page.User.Identity.IsAuthenticated gets its value from Page.User (obviously) which is unfortunately read-only and is not updated when you call FormsAuthentication.SignOut().

幸运的是 Page.User Context.User 可修改拉它的价值

Luckily Page.User pulls its value from Context.User which can be modified:

// HttpContext.Current.User.Identity.IsAuthenticated == true;

FormsAuthentication.SignOut();
HttpContext.Current.User =
    new GenericPrincipal(new GenericIdentity(string.Empty), null);

// now HttpContext.Current.User.Identity.IsAuthenticated == false
// and Page.User.Identity.IsAuthenticated == false

这在您退出当前用户,并希望没有做重定向与实际的页面响应是非常有用的。您可以检查 IsAuthenticated 在你需要它的同一页面请求中。

This is useful when you sign out the current user and wish to respond with the actual page without doing a redirect. You can check IsAuthenticated where you need it within the same page request.

这篇关于Page.User.Identity.IsAuthenticated仍然如此FormsAuthentication.SignOut后()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆