Home > Blockchain >  Force C# ASP.NET MVC web application to re-read web.config IPSettings
Force C# ASP.NET MVC web application to re-read web.config IPSettings

Time:12-28

I have a web application that is using ipSecurity settings to limit access by IP. We have some locations that don't have static IPs and thus need to update these settings.

We have another application that updates these location's IPs in a table in SQL and hits and endpoint in my web application so that these IPs get added to an XML file. This xml file is linked in web.config file (<ipSecurity configSource="ipSecurity.xml" />).

How do I force my web app to re-read these settings? It seems like they are not being updated once the XML is updated.

CodePudding user response:

When changes are made to the web.config file, the IIS will restart the app pool, when there are zero connections to the application. But at this might be a problem, restarting the app pool, would not be a good solution for you.

Updating the configuration file is still a good thing, as when the application is restartet, the new info will be served.

I will suggest using caching as a solution to your problem. When the application starts, you could load in the ip's into the cache from the web.config. Then, when the endpoint is hit with the new ip's, you can update the config file, and also override the current cashed value.

Hope this solution might help you.

CodePudding user response:

Is possible that rules are not updating because the web.config's content is not changed, since it's only linked by the "configSource" attribute.

If application pool restart is not a problem for you, you should update the web.config instead, avoiding using "configSource" attribute, and thus forcing IIS to restart the application pool to read the new configurations.

I think the web.config update will only recycle the pool and will not close any running requests. A small delay should be noticed by your clients until the application warms up.

If the IPs needs to be updated frequently in a day, this is not a good solution though.

  • Related