【问题标题】:Programmatically determine authentication mode以编程方式确定身份验证模式
【发布时间】:2011-10-27 04:07:01
【问题描述】:

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

【问题讨论】:

    标签: sharepoint


    【解决方案1】:

    看看 /_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
           }
    }
    

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

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

    看到它分配 his.rdo_authForms.Checked 的位置了吗?这就是你如何知道它是否使用表单身份验证。

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

    【讨论】:

      【解决方案2】:

      使用 Jon Schoning 的回答,我想出了以下代码来确定当前的身份验证模式是否为表单:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-09
        • 2019-01-02
        • 2018-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-15
        相关资源
        最近更新 更多