Programatically Recycle an IIS application pool

Source: Internet
Author: User

One of the specified Banes in my life is waiting for IIS to reset. when developing certain components, like a webpart or webcontrol, I often use a post-build event to GAC the Assembly and issue an iisreset. this is necessary for IIS to pick up the latest Assembly from the GAC. reloading ing the app pool also forces IIS to reload the Assembly, but I never cocould find a command I cocould issue from my post-build batch file to automate this. well, now I don't need to look because I just wrote my own utility to recycle the application pool:

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. directoryservices;

Namespace apppoolrecycler
{
Class Program
{
Static void main (string [] ARGs)
{
If (ARGs. length! = 2)
{
Console. writeline ("Usage: \ tapppoolrecycler.exe machine apppool \ n \ tapppoolrecycler.exe localhost mypool ");
Return;
}
Try
{
String smachine = ARGs [0];
String sapppool = ARGs [1];

String Spath = "IIS: //" + smachine + "/w3svc/apppools/" + sapppool;
Console. writeline (Spath );
Directoryentry W3SVC = new directoryentry (Spath );
W3SVC. Invoke ("recycle", null );
Console. writeline ("application pool recycled ");
}
Catch (exception ex)
{
Console. writeline ("error:" + ex. Message );
}
}
}
}

Now in my post build event I can GAC my assembly and recycle the app pool which is much faster than a reset.

Apppoolrecycler.exe sanpaula mssharepointportalapppool

Take a look at this blog entry for more information: http://blogs.aspitalia.com/daniele/post555/Riciclare-Application-Pool-IIS-Codice-CSharp.aspx

-----------------------

Update! I 've recently come into your SS a way to do this using a script which shoshould be installed on w2003:

C: \ windows \ system32 \ iisapp. vbs/A mssharepointportalapppool/R

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.