问题
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