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,

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sadlermdAuthor Commented:
works for me...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
OS Security

From novice to tech pro — start learning today.