Naor
Naor

Reputation: 24093

detect web.config has been changed

I created an HTTPModule that should log reauests and responses.
The parameters that tells the http module how to work located in the web.config.
But, in order to let the http module work with the latest values of the parameters, each request I read the parameters from the app.config.

Is there a way I can detect changes in the web.config so I can reload the http module parameters instead of reading them each time there is a response?

Upvotes: 3

Views: 2425

Answers (3)

user3086298
user3086298

Reputation: 310

what I have recently learnt is that when for example you change your web.config technically the asp.net application does not restart - it unloads. When you fire in the next request or start the app pool it then begins to load.

I'm filing this under a common misconception of asp.net developers ;)

Upvotes: 0

Simon Halsey
Simon Halsey

Reputation: 5480

@Ladislav & @velijoz are correct. The web.config is read once and the values stored in memory until the app restarts, because the web.config was changed for example.

Unless of course you're opening and reading the file directly. That would be a bad thing.

If the settings change regularly, you could put them in another file, read the values and store them in the cache with a cache dependency on the file. That way you could change the settings without restarting your app everytime. when you change the settings file, the cache dependency would invalidate the cache and your code could read the file again.

Simon

Upvotes: 2

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364389

You don't need to do that at all. You can load these properties only once and store them somewhere. Each time the web.config changes whole your ASP.NET application restarts and http module will have to initialize again.

Upvotes: 7

Related Questions