2

I need to restart an app pool from code, does anyone know how to do this? I have seen many examples for iis6 and most comments have been "It doesnt work"

So any ideas, or anyway to get IIS to watch a file and when it changes have the app pool restart?

2
  • A change in a file causing an Application Pool restart doesn't sound like a very robust solution. Can you give any more detail for why you are doing this? Commented Dec 15, 2009 at 13:20
  • We are doing this as we are using the url rewrite 1.1 and we need to restart the app pool everytime the urls change, as it stores them in memory when the pool spins up. The urls are generated by an admin system in an external file to the webconfig. Commented Dec 15, 2009 at 15:13

4 Answers 4

3

Using the application pool class would be the way to go, I think.

Kindness,

Dan

Sign up to request clarification or add additional context in comments.

4 Comments

Cool thanks, I have downloaded the iis7 sdk but still dont have the library? any ideas?
I think I have found the dll here: %WinDir%\System32\InetSrv Will give this a go
Well I get access denied to restart the appPool unless I use an Admin account as the appPool user, but thats not a good idea. Any ideas which groups should be allowed to do it?
What about creating your own group and user for your app?
1

Actually appending a single space ' ' to the end web.config will cause a Application restart.

In the web app folder (inetpub\wwwroot\webapp) create a bat file (rest.bat )with

echo   >> web.config

If you run the batch file you will get a recycle

Comments

0

Easier way.. Why not when the file you are looking at changes and you want to recycle the application just change a key in the Web.config. Any change to Web.config causes your application to recycle..

Comments

0

Rather than do it this way (recycle the pool) why not use a cache dependency based om the file? there is an example of doing it here with an xml file. That way no more app recycles.

XmlDocument urls = new XmlDocument();
        urls.Load(Server.MapPath("pathetourlfile.xml"));
        CacheDependancy dependancy = new CacheDependency(Server.MapPath("pathetourlfile.xml"))
        Cache.Insert("URLS", urls, dependency)

1 Comment

Thanks for the example, we have litterally just removed the whole app pool restart code as we have found a better way of doing what we were trying to do (back to how I had it in IIS6, we were just missing an element for the webconfig). :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.