ServerManager CommitChanges 进行更改时略有延迟
我对 ServerManager 类(来自 Microsoft.Web.Administration 程序集)有一个小问题,我希望你们中的一些人可以帮助我。
基本上,我需要在站点内创建一个新应用程序(使用 IIS 7.5),并将用户重定向到同一事件内的新应用程序。此功能是使用 mvc 3/c# 在 .net Web 应用程序内实现的。
这是我的代码:
ServerManager iisManager = new ServerManager();
Site mySite = iisManager.Sites["mySitesName"];
ApplicationCollection applications = mySite.Applications;
Application app = applications.Add(newapp, physicalPath);
app.ApplicationPoolName = "myAppPool";
iisManager.CommitChanges();
iisManager.Dispose();
return new RedirectResult("http://localhost/" + newapp);
我认为此代码的问题在于 ServerManager 提交更改似乎略有延迟,并且重定向到 IIS 中新添加的应用程序返回“HTTP 错误 404.0 - 未找到”,因为从 ServerManager 提交的更改没有完成了(我认为)。如果我在 404 之后刷新页面,则会加载新应用程序。
非常感谢任何帮助或想法。
干杯!
i have a little problem with the ServerManager class (from the Microsoft.Web.Administration assembly) and i hope some of you can help me out.
Basically I need to create a new application inside a site (using IIS 7.5) and redirect the user to the new application, inside the same event.This functionality is implemented inside a .net web app using mvc 3/c#.
Here is my code:
ServerManager iisManager = new ServerManager();
Site mySite = iisManager.Sites["mySitesName"];
ApplicationCollection applications = mySite.Applications;
Application app = applications.Add(newapp, physicalPath);
app.ApplicationPoolName = "myAppPool";
iisManager.CommitChanges();
iisManager.Dispose();
return new RedirectResult("http://localhost/" + newapp);
I think the problem with this code is that ServerManager seems to submit changes with a slight delay and the redirect to the newly added application in IIS returns "HTTP Error 404.0 - Not Found" because the changes commited from ServerManager are not finished (i think). If I refresh the page after the 404, the new application loads.
Any help or idea is greatly appreciated.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎关于这种“延迟”的文档很难找到......或者不存在。最后我最终使用了“Thread.Sleep”,就像 iis.net 上建议的那样。
希望这可以帮助其他有需要的人。
干杯!
Seems that documentation about this "delay" is very hard to find...or not existent. In the end I ended up using "Thread.Sleep" like it was suggested on iis.net.
Hope this helps others in need.
Cheers!