1

I am trying to do customAuthorization in MVC when the authentication mode is "windows"

    public override void OnAuthorization(AuthorizationContext filterContext)
    {

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

But always IsAuthenticated is returning false. I don't know how to invoke windows authentication before the onAuthorization(..).

But when i do like this:

public override void OnAuthorization(AuthorizationContext filterContext)
    {

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

The onAuthorization() method is hitting repeatedly because of the base.onAuthorization() and in the second attempt IsAuthenticated is returning true.

May i know the reason for this behavior?

When i googled results came up saying that IsAuthenticated will be true in Forms Authentication mode but not in Windows mode. As mentioned in the below link

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

Please Help me.

bharath
  • 89
  • 2
  • 10
  • `OnAuthorization` is called when authorization is *requested*. Simply, the user is never authenticated yet at this point, because that happens later. – Chris Pratt Jul 07 '14 at 20:33
  • Hi, The issue is solve. I disabled allowanonymous property in IIS server settings and it started working as expected i.e the user is being authenticated before hitting onauthorization(..). – bharath Jul 08 '14 at 18:57

1 Answers1

2

The issue is solved. I disabled allowanonymous property in IIS server settings and it started working as expected i.e the user is being authenticated before hitting onauthorization(..).

bharath
  • 89
  • 2
  • 10