简体   繁体   English

刷新IIS站点自定义设置,而无需重新启动它

[英]Refresh IIS site custom settings without restarting it

I have a custom settings file ( Settings.xml ) where I specify all that I need. 我有一个自定义设置文件( Settings.xml ),可以在其中指定所需的所有内容。 When changeing that file while running the website the site, of course, restart. 当然,在运行网站时更改该文件时,请重新启动网站。

Settings.xml is read into an object that have the same structure as the xml and then I work with the Settings object 将Settings.xml读入与xml具有相同结构的对象中,然后使用Settings对象

private static readonly XDocument Settings = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");

The site runs in IIS 8.5. 该站点在IIS 8.5中运行。

Is it possible to update Settings.xml without forceing the website to restart? 是否可以在不强制网站重新启动的情况下更新Settings.xml

Is it the IIS that automatically restart? 是IIS自动重新启动吗?

You can read your setting on every file change like this: 您可以按以下方式读取每个文件更改的设置:

private static DateTime? _lastSettingRead;
private static XDocument _cahedSettings;
private static XDocument Settings
{
    get
    {
        var settingsPath = AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml";
        //Get last change Settings file datetime
        var lastSettingChange = System.IO.File.GetLastWriteTime(settingsPath);
        //If we read first time or file changed since last read
        if (!_lastSettingRead.HasValue || lastSettingChange > _lastSettingRead)
        {
            _lastSettingRead = lastSettingChange; //change read date
            _cahedSettings = XDocument.Load(settingsPath); //load settings to field
        }
        return _cahedSettings; //return cached settings from field
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM