locked
detect custom config is modified RRS feed

  • Question

  • we have a custom config in asp.net using attribute restartOnExternalChanges="false" to avoid app restart when the content is changed.

    now i need a feature to detect changes, the only option is ConfigurationSection.IsModified() method, but tested it doesn't get invoked/triggered when i made changes to the file.

    how to detect custom config file changes?

    Tuesday, March 12, 2013 4:27 AM

Answers

  • You can use FileSystemWatcher with the path returned by Server.MapPath() to the file to detect the change. That's how the .NET runtime detect when to recompile the website (although it monitors a folder instead of just a file) internally.

    By the way, do you know that restartOnExternalChanges has no effect on ASP.NET Applications? Maybe your code isn't triggered because the web application is restarting.
    • Edited by cheong00Editor Tuesday, March 12, 2013 6:13 AM
    • Marked as answer by Kelmen Thursday, March 14, 2013 4:03 AM
    Tuesday, March 12, 2013 5:56 AM
    Answerer

All replies

  • You can use FileSystemWatcher with the path returned by Server.MapPath() to the file to detect the change. That's how the .NET runtime detect when to recompile the website (although it monitors a folder instead of just a file) internally.

    By the way, do you know that restartOnExternalChanges has no effect on ASP.NET Applications? Maybe your code isn't triggered because the web application is restarting.
    • Edited by cheong00Editor Tuesday, March 12, 2013 6:13 AM
    • Marked as answer by Kelmen Thursday, March 14, 2013 4:03 AM
    Tuesday, March 12, 2013 5:56 AM
    Answerer
  • i prefer look for other alternative apart from the FileSystemWatcher due to security concern.

    if really no choice then I try it.

    the restartOnExternalChanges  do works as we expected, running ASP.NET 4.

    Tuesday, March 12, 2013 10:10 AM
  • If you have security concern, I'd recommand you to write a Windows Service to handle this.

    The service will just host the FileSystemWatcher, and use webclient to access a particular URL of your web application on Change event. I think running as limited users like NetworkService or LocalService would be enough. (You have to give the folder access to LocalService if you want to use it because by default only NetworkService of the two has access to web folders)

    The handler of that URL will just have one function, that is to reload the configuration settings.


    Wednesday, March 13, 2013 2:17 AM
    Answerer
  • Hi Kelmen,

    Welcome to the MSDN Forum.

    How about this way: http://msdn.microsoft.com/en-us/library/ff647832.aspx  

    If you use a custom file to store configuration information, you can detect changes to the file using a SectionChangeHandler. The following code shows how you can detect changes to Logging Application Block configuration in a custom file named Logging.config.

    You can put the changeable part in a custom config file.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 13, 2013 12:34 PM
  • we are not using microsoft enterprise/app block lib

    we are using the Config Section Designer http://csd.codeplex.com/

    too bad there's no proper way to do it using the .NET lib.

    Thursday, March 14, 2013 2:19 AM