Use Asp.net to reclaim the iis6.0 application pool

Source: Internet
Author: User
Because the website uses a large number of caches, sometimes cache errors may occur, resulting in Program Exception. In this case, you need to reclaim an application pool.

In the past, I used to connect to the server through the remote desktop, and then right-click the application pool to recycle it. This is troublesome. I found the following method to implement it.

It is actually a common Asp.net page, and a button is added for recycling. The main program is as follows:CopySave

Protected VoidStartstoprecycleapp (StringMethod ){StringApppoolname =This. Tbappname. Text. Trim ();// String method = "recycle ";Try{Directoryentry apppool =NewDirectoryentry ("IIS:// Localhost/w3svc/apppools ");Directoryentry findpool = apppool. Children. Find (apppoolname,"Iisapplicationpool"); Findpool. Invoke (method,Null); Apppool. commitchanges (); apppool. Close (); lbmsg. Text =String. Format ("Application pool {0} {1} succeeded", Apppoolname, method );}Catch(Exception ex) {lbmsg. Text =String. Format ("Application pool {0} {2} failed: {1 }", Apppoolname, Ex. Message, method );}}

Tbappname is a textbox used to enter the name of the application pool, for example, defaappapppool ".
When method = "recycle", it is recycled. If it is set to "start", it is started. If it is set to "stop", it is stopped.

Note:

1. system must be introduced. directoryservices package
2. the user must have a high permission for the application running this program. You can independently provide the application program for this program, or create a virtual directory to simulate advanced users (such as administrators or systems) in the preparation. Otherwise, the application will throw an "Access Denied" exception.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.