views:

410

answers:

4

Hi

I have the following defined in my web.config (

<rewriteMaps configSource="Rewrites.config"  />

I have a CONFIG file that can be regenerated by an administrator via a web page. However when this file changes then the new changes are not picked up until the application recycles.

My queestion is that I want to be able to recycle the application pool automatically when the file changes, is this possible? or is their a better approach?

Maybe the question should be is there another way for the rewrite maps to be dynamically used by the application?

I am using IIS7 in Integrated Mode running under Medium Trust.

Thanks Richard

A: 

Take a look at this if you are interested in programaticaly recycling the app pool, Recycle App Pool, there is also a link at the bottom for recycling via a script

Simon Wilson
Hi, I dont think this will work in Medium Trust level as it calls an EXE outside the web root. Sorry but this is not the answer I am looking for
Rippo
A preferred method of restarting a single app is HttpRuntime.UnloadAppDomain(). It doesn't require the app to know its app pool. However, I believe this requires a higher level of trust than medium, so it won't help your situation. Posting here for anyone following this conversation.
Jerry Bullard
A: 

If the administrator web page has access to the application directory, just have the web page re-write, or fake a modification to, the web.config after it writes the external rewrites.config file. The application pool recycle will happen normally because of the change to web.config, which will ultimately lead to the external configuration being re-read.

There are a couple of downsides to this approach:

  1. in a web farm scenario, you have to re-write the web.config for every node in the farm to get a consistent state.
  2. this reloading of the application forces a recompilation of the web site, which could result in a 503 error unless your running in a web garden scenario.

A better approach might be to let the Administrator re-write the file normally via the web page like you do today, then have them run a script like @Simon suggested. The administrator likely already has elevated privileges and should be able to execute a script that calls iisapp.vbs to recycle a specific application pool and not a full iisreset.

Hope that helps!
Z

Zach Bonham
+1  A: 

A hack way of recycling just your app pool is to add then delete a subfolder. This will trigger an app recycle.

JustLoren
Does this work across a web farm?
Rippo
If your web farm is using a centralized file server, yeah.
JustLoren
A: 

Looks like I need to rethink my strategy, thanks for answers guys

Rippo