0

应用代码时

            using (ServerManager serverManager = new ServerManager())
            {
                var site = serverManager.Sites.SingleOrDefault(s => s.Name == siteName);
                // some logic to add sites, set application pool. 
                // But not creating new ServerManager instances.


                serverManager.CommitChanges();
            }

会有一些机会抛出异常

System.IO.FileLoadException: Filename: \\?\C:\windows\system32\inetsrv\config\applicationHost.config
Error: Cannot commit configuration changes because the file has changed on disk

at Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager.CommitChanges()
at Microsoft.Web.Administration.ConfigurationManager.CommitChanges()
at Microsoft.Web.Administration.ServerManager.CommitChanges()

我们也尝试过从using子句移开并使用单例ServerManager,但同样的问题仍然存在。

我们正在使用 Microsoft.Web.Administration 11.0.0 包。

目前,我们通过 catch 修复它并在 catch 中serverManager.CommitChanges()应用iisreset

但是,如果有人知道根本原因/如何解决它,那就太好了。

4

0 回答 0