以编程方式创建新的 IIS 网站时,如何将其添加到现有应用程序池?
我已经成功地自动化了创建新 IIS 网站的过程,但是我编写的代码并不关心应用程序池,它只是添加到 DefaultAppPool 中。不过,我想将这个新创建的网站添加到现有的应用程序池中。
这是我用来创建新网站的代码。
var w3Svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", webserver));
var newsite = new object[] { serverComment, new object[] { serverBindings }, homeDirectory };
var websiteId = w3Svc.Invoke("CreateNewSite", newsite);
site.Invoke("Start", null);
site.CommitChanges();
<更新>
尽管这与问题没有直接关系,但这里有一些上面使用的示例值。这可能有助于某人更轻松地准确理解上面的代码在做什么。
- webServer: "localhost"
- serverComment: "testing.dev"
- serverBindings: ":80:testing.dev"
- homeDirectory: "c:\inetpub\wwwroot\testing\" <
/update>
如果我知道我想要此网站所在的应用程序池的名称,我如何找到它并将此网站添加到其中?
I have successfully automated the process of creating a new IIS website, however the code I've written doesn't care about application pools, it just gets added to DefaultAppPool. However I'd like to add this newly created site to an existing application pool.
Here is the code I'm using to create the new website.
var w3Svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", webserver));
var newsite = new object[] { serverComment, new object[] { serverBindings }, homeDirectory };
var websiteId = w3Svc.Invoke("CreateNewSite", newsite);
site.Invoke("Start", null);
site.CommitChanges();
<update>
Although this is not directly related to the question, here are some sample values being used above. This might help someone understand exactly what the code above is doing more easily.
- webServer: "localhost"
- serverComment: "testing.dev"
- serverBindings: ":80:testing.dev"
- homeDirectory: "c:\inetpub\wwwroot\testing\"
</update>
If I know the name of the application pool that I'd like this web site to be in, how can I find it and add this site to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须在虚拟目录(而不是 Web 服务器)上分配 AppPool 并将 AppIsolated 属性设置为 2,这意味着 pooled-process ;)
http://msdn.microsoft.com/en-us/library/ms525598%28v=VS.90%29.aspx
相关链接中的代码示例:
请注意,如果您没有显式向应用程序添加新的虚拟目录,则
metabasePath
将仅为“IIS:///W3SVC/
”。 siteID>/Root
"You have to assign the AppPool on the virtual dir (not the webserver) and set the AppIsolated property to 2 which mean pooled-process ;)
http://msdn.microsoft.com/en-us/library/ms525598%28v=VS.90%29.aspx
Relevant code sample from link:
Note that if you are not explicitly adding a new virtual directory to the application, the
metabasePath
will simply be "IIS://<servername>/W3SVC/<siteID>/Root
"您需要从
IIS://{0}/W3SVC/AppPools
获取 AppPool,并将其附加到site
的AppPoolId
。像这样的东西:You need to get the AppPoolfrom
IIS://{0}/W3SVC/AppPools
, and attach it to thesite
'sAppPoolId
. Something like:site.Properties["AppPoolId"][0]= "池名称";
site.Properties["AppPoolId"][0]= "poolname";