How to verify Windows Authentication is enabled...

Using: IIS 7, Windows Server 2008, C#, .NET Fx 3.5

How do I, in C#, determine if Windows Authentication is enabled in IIS?

Thanks in advance,

Rick
sadlermdAsked:
Who is Participating?
 
sadlermdAuthor Commented:
this works for me:

private bool WindowsAuthenticationEnabledInIIS()
{
            var enabled = false;
            const string iisPath = "IIS://localhost/W3SVC/1/Root/myWebApp";
            if (DirectoryEntry.Exists(iisPath))
            {
                using (var myWebApp = new DirectoryEntry(iisPath))
                {
                    var authNtlm = myWebApp.Properties["AuthNTLM"][0];
                    if (authNtlm.Equals(true)) enabled = true;
                }
            }
            return enabled;
}
0
 
sadlermdAuthor Commented:
Is there a way in code to ask IIS if Windows Auth has bee enabled?

I'm implementing a mixed mode auth solution where Forms is the default and, if the user is accessing the site on an intranet, I want to use Windows auth - but only if Windows Auth is enabled in IIS.
0
 
sadlermdAuthor Commented:
works for me...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.