tags:

views:

125

answers:

1

Is there a way to programmatically determine if a SharePoint 2007 web application is using Forms authentication? I guess one way might be to read it from the web.config but I was wondering if there is some property exposed in the API.

+3  A: 

Take a look at how /_admin/Authentication.aspx does it in Central Admin:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    string g = base.Request.QueryString["WebAppId"];
    this.webApp = (SPWebApplication) SPConfigurationDatabase.Local.GetObject(new Guid(g));
    this.zone = (SPUrlZone) Enum.Parse(typeof(SPUrlZone), base.Request.QueryString["Zone"]);
    this.lb_Zone.Text = SPHttpUtility.HtmlEncode(SPAlternateUrl.GetZoneName(this.zone));
    SPIisSettings iisSettings = this.webApp.IisSettings[this.zone];

    // CODE ELIDED

        if (AuthenticationMode.Windows != iisSettings.AuthenticationMode)
        {
            if (AuthenticationMode.Forms != iisSettings.AuthenticationMode)
            {
                // CODE ELIDED
            }
            else
            {
                this.rdo_authForms.Checked = true;
            }

            // CODE ELIDED
       }
}

The part you are interested in is where it uses iisSettings.AuthenticationMode to determine if it is Forms Auth or not. So the trick is to correctly obtain a reference to SPIisSettings that is relevant to your webapp and zone. Getting to that point is where all the work needs to be done.

You'll need to parameterize parts of this code so that information to identify and obtain references to the webApp and Zone are passed in.

See where it assigns his.rdo_authForms.Checked? that's how you know if it's using forms auth.

Also, this implies that you need to know which Zone of the web application you are looking at to see if Forms Authentication is enabled

Jon Schoning