我有一個ASP.NET MVC 4應用程序。HttpContext.Current null在FileSystemWatcher內
另外我有一個XML文件位於我的應用程序的根目錄。
無論何時管理員更改此文件,我都希望應用程序瞭解它並閱讀新值。
...
FileSystemWatcher Watcher = new FileSystemWatcher();
Watcher.Changed += new FileSystemEventHandler(OnChanged);
...
private void OnChanged(object source, FileSystemEventArgs e) {
var path = HttpContext.Current.Server.MapPath("~/"))
}
每次HttpContext.Current
似乎都是空的。如何獲取我的應用程序的根文件夾,如果這不起作用?