HttpContext.Current.User.Identity.IsAuthenticated返回false

时间:2012-12-20 13:57:01

标签: c# asp.net authentication

我有一个奇怪的问题。

我有一个包含以下代码的页面。

if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Server.Transfer(@"~/Views/Public/Unauthorised.aspx");
        return;
    }

出于某种原因,对于一个用户(我们将其缩小到他的单个机器和Windows登录配置文件),IsAuthenticated总是返回false。即使他已登录网站,也可以导航到需要经过身份验证的用户的其他页面。除了这一页。

我们检查了机器是否接受了所有Cookie,我们仍然遇到同样的问题。我不知道从哪里开始......有什么建议吗?

1 个答案:

答案 0 :(得分:5)

至少有两种已知案例可以导致此行为。

第一种情况,当您在requireSSL="true"上的身份验证会话中设置web.config并从非安全页面调用该功能时。因此,如果您使用requireSSL="true"

,请仔细检查网页是否安全
Debug.Assert(Request.IsSecureConnection, "The IsAuthenticated will fail.");
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
    Server.Transfer(@"~/Views/Public/Unauthorised.aspx");
    return;
}

第二种情况,如果您未在web.config中的身份验证会话中再次设置domain="site.com",并且您尝试从{{1}一次请求Cookie而另一个来自www.yoursitename.com。在这种情况下,身份验证cookie是不同的,它将失败。所以在web.config上设置该参数。

yoursitename.com