Clicky

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

asked 12/12/2011 08:38

sadlermd's gravatar image

sadlermd ♦♦


4 Answers:
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.
link

answered 2011-12-13 at 01:47:55

sadlermd's gravatar image

sadlermd

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;
}
link

answered 2011-12-13 at 06:13:57

sadlermd's gravatar image

sadlermd

works for me...

link

answered 2011-12-13 at 08:27:13

sadlermd's gravatar image

sadlermd

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 12/12/2011 08:38

Seen: 311 times

Last updated: 12/17/2011 05:18