用asp.net來回收IIS6.0應用程式集區

來源:互聯網
上載者:User
網站由於使用比較多的緩衝,有時會出現緩衝錯誤,導致程式異常,這個時候需要回收一個應用程式集區就可以了。

以前每次都是通過遠端桌面連線到伺服器,然後在應用程式集區上右擊》回收,感覺比較麻煩,於時找了如下的一個辦法來實現。

其實就是普通的一個asp.net頁面,加上一個按鈕,進行回收,主要程式如下:  複製  儲存

protected void StartStopRecycleApp(string method){string AppPoolName = this.tbAppName.Text.Trim();//string method = "Recycle";try{DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");        DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");findPool.Invoke(method, null);appPool.CommitChanges();appPool.Close();lbMsg.Text = string.Format("應用程式集區{0}{1}成功", AppPoolName, method);}catch (Exception ex){lbMsg.Text = string.Format("應用程式集區{0}{2}失敗:{1}", AppPoolName, ex.Message, method);}}

tbAppName是一個textbox,用來輸入應用程式集區的名字,如“DefaultAppPool”。
當method="Recycle"時就是回收,為“Start”時是啟動,為“Stop”時是停止。

注意:

1. 必須引入System.DirectoryServices包
2. 運行此程式的應用程式也的使用者必須許可權比較高,可以單獨為此程式提供應用程式程,或者建立一個虛擬目錄在配製裡類比進階使用者(如administrators或者system),否則應用程式會拋出“拒絕訪問”的異常。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.