快速业务通道

手动创建应用程序池,并自动将程序assign到新创建的池中(MSI制作)

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-20

我在部署ASP.net应用程序的时候,在IIS中都是创建在默认的应用池当中.我们能否在部署的时候创建 自己的应用池呢?

本文就带你一起创建自己的应用池!

1 using System;
2 using System.IO;
3 using System.DirectoryServices;
4 using System.Reflection;
5 using System.Runtime.InteropServices;
6 using System.Collections;
7
8 namespace System_DirectoryServices_DirectoryEntry_ConfigIIS
9 {
10   class Program
11   {
12     static void Main(string[] args)
13     {
14
15
16
17 CreateAppPool("IIS://Localhost/W3SVC/AppPools", "MyAppPool");
18
19
20
21 CreateVDir("IIS://Localhost/W3SVC/1/Root", "MyVDir", "D:\\Inetpub\\Wwwroot");
22
23
24
25 AssignVDirToAppPool("IIS://Localhost/W3SVC/1/Root/MyVDir", "MyAppPool");
26
27
28
29 }
30
31
32
33 static void CreateAppPool(string metabasePath, string appPoolName)
34 {
35   //  metabasePath is of the form "IIS://<servername>/W3SVC/AppPools"
36   //    for example "IIS://localhost/W3SVC/AppPools"
37   //  appPoolName is of the form "<name>", for example, "MyAppPool"
38   Console.WriteLine("\nCreating application pool named {0}/{1}:", metabasePath, appPoolName);
39
40   try
41   {
42     if (metabasePath.EndsWith("/W3SVC/AppPools"))
43     {
44       DirectoryEntry newpool;
45       DirectoryEntry apppools = new DirectoryEntry(metabasePath);
46       newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
47       newpool.CommitChanges();
48       Console.WriteLine(" Done.");
49     }
50     else
51       Console.WriteLine(" Failed in CreateAppPool; application pools can only be created in the */W3SVC/AppPools node.");
52   }
53   catch (Exception ex)
54   {
55     Console.WriteLine("Failed in CreateAppPool with the following exception: \n {0}", ex.Message);
56   }
57 }
58
59
60
61 static void CreateVDir(string metabasePath, string vDirName, string physicalPath)
62 {
63   //  metabasePath is of the form "IIS://<servername>/<service>/<siteID>/Root[/<vdir>]"
64   //    for example "IIS://localhost/W3SVC/1/Root"
65   //  vDirName is of the form "<name>", for example, "MyNewVDir"
66   //  physicalPath is of the form "<drive>:\<path>", for example, "C:\Inetpub\Wwwroot"
67   Console.WriteLine("\nCreating virtual directory {0}/{1}, mapping the Root application to {2}:",
68       metabasePath, vDirName, physicalPath);
69
70   try
71   {
72     DirectoryEntry site = new DirectoryEntry(metabasePath);
73     string className = site.SchemaClassName.ToString();
74     if ((className.EndsWith("Server")) || (className.EndsWith("VirtualDir")))
75     {
76       DirectoryEntries vdirs = site.Chi

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号