【问题标题】:Always HttpContext.Current.User.Identity.IsAuthenticated = false in MVC4 with windows authentication mode and not working correctly在具有 Windows 身份验证模式的 MVC4 中始终 HttpContext.Current.User.Identity.IsAuthenticated = false 并且无法正常工作
【发布时间】:2014-07-07 20:06:02
【问题描述】:

当身份验证模式为“windows”时,我正在尝试在 MVC 中进行 customAuthorization

    public override void OnAuthorization(AuthorizationContext filterContext)
    {

        #region if
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        { .......}
     }

但 IsAuthenticated 总是返回 false。我不知道如何在 onAuthorization(..) 之前调用 windows 身份验证。

但是当我这样做时:

public override void OnAuthorization(AuthorizationContext filterContext)
    {

        #region if
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        { .......}else{
         **base.OnAuthorization(filterContext);**
         }
     }

由于 base.onAuthorization() 的原因,onAuthorization() 方法重复命中,并且在第二次尝试中 IsAuthenticated 返回 true。

我可以知道这种行为的原因吗?

当我用谷歌搜索结果时说 IsAuthenticated 在表单身份验证模式下将是真的,但在 Windows 模式下不会。如以下链接所述

http://www.anujvarma.com/windows-ad-authentication-and-the-authorize-attributelogin-popup/

请帮帮我。

【问题讨论】:

  • OnAuthorization请求授权时被调用。简而言之,此时用户从未经过身份验证,因为那会在以后发生。
  • 您好,问题已解决。我在 IIS 服务器设置中禁用了 allowanonymous 属性,它开始按预期工作,即在点击 onauthorization(..) 之前对用户进行身份验证。

标签: c# asp.net-mvc asp.net-mvc-4 windows-authentication custom-authentication


【解决方案1】:

问题解决了。我在 IIS 服务器设置中禁用了 allowanonymous 属性,它开始按预期工作,即在点击 onauthorization(..) 之前对用户进行身份验证。

【讨论】:

  • 也解决了我的问题。谢谢。
猜你喜欢
  • 2012-05-07
  • 1970-01-01
  • 2016-11-09
  • 1970-01-01
  • 2014-11-17
  • 2012-10-20
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
相关资源
最近更新 更多