2009-11-25 63 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) { ... } 
相關問題