[英]Refresh IIS site custom settings without restarting it
我有一個自定義設置文件( Settings.xml ),可以在其中指定所需的所有內容。 當然,在運行網站時更改該文件時,請重新啟動網站。
將Settings.xml讀入與xml具有相同結構的對象中,然后使用Settings
對象
private static readonly XDocument Settings = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Settings.xml");
該站點在IIS 8.5中運行。
是否可以在不強制網站重新啟動的情況下更新Settings.xml ?
是IIS自動重新啟動嗎?
您可以按以下方式讀取每個文件更改的設置:
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.