2

我有一個ActiveDirectoryMembershipProvider,並且我有一個SQLMembershipProvider(本質上,它是一個ASP.Net應用程序,用戶爲應用程序生成的用戶和來自活動目錄的用戶都可以登錄)。我想設置登錄控制器,以便在本地用戶登錄時,如果AD提供程序無法與AD服務器通話,則當另一用戶嘗試登錄時,它將重新初始化ADProvider。重新初始化MembershipProvider ASP.NET

據我所知,應用程序在任何一個被調用時初始化兩個提供程序。 ADProvider會嘗試連接,如果無法連接,則會引發錯誤。 我目前發現這個錯誤並且默默丟棄。本地用戶可以登錄,但是當我重啓我的AD服務器時,我似乎找不到讓ADProvider嘗試重新連接的方法。我試圖再次調用initialize(),但它會拋出一個'已經初始化'的錯誤。

如果我需要創建自己的,很好,我希望有一些配置或簡單的方法,我失蹤。

回答

0

我終於想通了什麼,在這種情況下,這樣做:

//create our own AD Provider 
    private System.Web.Security.ActiveDirectoryMembershipProvider base_provider; 

    private bool initialised = false; 

    //these values are saved when Init if first called by the Membership Collection. 
    //So that I can pass them back into the new base_provider when it is made. 
    private string name = null; 
    private System.Collections.Specialized.NameValueCollection config; 
    private Exception init_exception; 

    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) 
    { 
     this.name = name; 
     this.config = config; 

     try 
     { 
      base_provider = new System.Web.Security.ActiveDirectoryMembershipProvider(); 

      base_provider.Initialize(name, config); 
      initialised = true; 
     } 
     catch (Exception e) 
     { 
      this.base_provider = null; 
      init_exception = e; 
     } 
    } 

    public override System.Web.Security.MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) 
    { 
     if (!initialised) this.Initialize(this.name, this.config); 

     //just a custom exception that my Membership object (that handles calling the two providers) picks up on 
     if (base_provider == null) throw new NotInitialisedException(this.init_exception.Message); 

     return base_provider.GetAllUsers(pageIndex, pageSize, out totalRecords); 
    } 

    .... 

那麼對於我不想實現任何方法(例如,我不想改變AD服務器上的任何數據,只是想列出並驗證用戶)我只是有一個NotImplementedException