ServerManager CommitChanges makes changes with a slight delay

情到浓时终转凉″ 提交于 2020-01-13 04:27:46

问题


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!


回答1:


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!



来源:https://stackoverflow.com/questions/7446632/servermanager-commitchanges-makes-changes-with-a-slight-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!