2009-11-25 60 views
3

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

回答

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,以确定它是否是窗体身份验证或不。所以诀窍是正确获得与您的web应用程序和区域相关的SPIisSettings的引用。到达这一点是所有工作都需要完成的地方。

你需要这个参数的部分代码,使信息识别和获取到Web应用程序和区域的引用中传递。

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

而且,这意味着你需要知道哪些区域中的Web应用程序,你正在寻找,看是否Forms身份验证启用

3

使用乔恩Schoning的答案,我想出了下面的代码,以确定目前的认证模式为表格:

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