ServerManager CommitChanges稍有延迟即可进行更改 [英] ServerManager CommitChanges makes changes with a slight delay

查看:102
本文介绍了ServerManager CommitChanges稍有延迟即可进行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ServerManager类(来自Microsoft.Web.Administration程序集)有一点问题,希望大家能帮助我.

基本上,我需要在站点内(使用IIS 7.5)创建一个新应用程序,并将用户重定向到同一事件内的新应用程序.此功能是在使用mvc 3/c#的.net Web应用程序内实现的./p>

这是我的代码:

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之后刷新页面,则会加载新的应用程序.

任何帮助或想法都将不胜感激.

干杯!

解决方案

似乎很难找到有关此延迟"的文档...或者根本不存在.最后,我最终使用了 iis.net 上建议的"Thread.Sleep".

希望这可以帮助需要帮助的人.

干杯!

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!

这篇关于ServerManager CommitChanges稍有延迟即可进行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆