以编程方式确定认证模式

3

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

2个回答

5
请看中央管理界面 /_admin/Authentication.aspx 的做法:
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
       }
}

您感兴趣的部分是使用iisSettings.AuthenticationMode来确定是否为Forms Auth。因此,关键是正确获取与您的Web应用程序和区域相关的SPIisSettings的引用。要达到这一点,需要完成所有工作。
您将需要参数化代码的某些部分,以便传递用于识别和获取对Web应用程序和Zone的引用的信息。
请注意,它分配了his.rdo_authForms.Checked的位置?这就是您知道它是否正在使用表单验证的方式。
此外,这意味着您需要知道您正在查看哪个Web应用程序的Zone,以查看是否启用了表单验证。

3

根据Jon Schoning的答案,我得出了以下代码来确定当前的身份验证模式是否为表单:

if (SPContext.Current.Site.WebApplication.IisSettings[SPContext.Current.Site.Zone].AuthenticationMode == System.Web.Configuration.AuthenticationMode.Forms) { ... }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接