views:

309

answers:

4

Hi all,

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?

+1  A: 

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

Kindness,

Dan

Daniel Elliott
Cool thanks, I have downloaded the iis7 sdk but still dont have the library? any ideas?
JamesStuddart
I think I have found the dll here: %WinDir%\System32\InetSrvWill give this a go
JamesStuddart
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?
JamesStuddart
What about creating your own group and user for your app?
Daniel Elliott
A: 

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..

Markive
A: 

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

ggonsalv
A: 

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)
Pharabus
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). :)
JamesStuddart