开发者

ServerManager CommitChanges makes changes with a slight delay

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!


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜