以编程方式确定验证模式

Ric*_*ter 3 sharepoint

有没有办法以编程方式确定SharePoint 2007 Web应用程序是否正在使用Forms身份验证?我想有一种方法可能是从web.config读取它,但我想知道API中是否有一些属性暴露.

Jon*_*ing 5

看看/_admin/Authentication.aspx如何在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
       }
}
Run Code Online (Sandbox Code Playgroud)

您感兴趣的部分是使用iisSettings.AuthenticationMode来确定它是否为Forms Auth.因此,诀窍是正确获取与您的webapp和区域相关的SPIisSettings的引用.达到这一点是需要完成所有工作的地方.

您需要参数化此代码的各个部分,以便传入用于标识和获取对webApp和区域的引用的信息.

看看它分配了他的位置.rdo_authForms.Checked?这就是你如何知道它是否正在使用表单auth.

此外,这意味着您需要知道正在查看的Web应用程序的哪个区域,以查看是否启用了表单身份验证