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

我有一个奇怪的问题。

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

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

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

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

至少有两种已知的案例可以解决这种问题。

第一种情况是在web.config上的Authentication会话中设置requireSSL="true" ,并从非安全页面调用该函数。 因此,如果您使用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中的身份validation会话中再次设置domain="site.com"时,您尝试从www.yoursitename.com一次请求cookie,另一次从yoursitename.com请求cookie 。 在这种情况下,身份validationcookie是不同的,它将失败。 所以在web.config上设置该参数。