惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Cloudflare Blog
L
LangChain Blog
T
Tenable Blog
GbyAI
GbyAI
C
Cybersecurity and Infrastructure Security Agency CISA
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
量子位
Cloudbric
Cloudbric
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
S
Secure Thoughts
P
Privacy & Cybersecurity Law Blog
S
Securelist
S
Schneier on Security
F
Full Disclosure
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Privacy International News Feed
宝玉的分享
宝玉的分享
A
About on SuperTechFans
博客园 - 【当耐特】
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
H
Heimdal Security Blog
Y
Y Combinator Blog
月光博客
月光博客
H
Hacker News: Front Page
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
N
Netflix TechBlog - Medium

博客园 - 陋室

成功与一截树枝 sql 操作全集-整理收藏 JavaScript使用技巧精萃(转载) ASP.NET 中在指定的位置处插入字符 提示按下大写键的控件:MQTool(提供下载) 如何在mail的正文显示图片 NET设计模式之一:装饰模式(Decorator Pattern) 微软AJAX 教学系列第一讲:ScriptManager控件 微软AJAX 教学系列第一讲:局部刷新Partial Page Updates(翻译) 李开复:21世纪最需要的7种人才 Building a File Service 超卓越的你_读完后让你恢复自信 how to write professional business letters? 到底什么是托管,什么是非托管的研究 数据库设计中的五个范式(本文转载,收藏下) 如何直接用XML做数据源? ASP.NET程序的优化建议<转> ASP.NET部署与安装_MSI制作图文教程. Understand SQL Cache Notifications
在打包的时候,创建应用程序池,并自动将程序assign到新创建的池中(MSI制作)
陋室 · 2008-04-10 · via 博客园 - 陋室

 我在在部署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.Children;
 77       DirectoryEntry newVDir = vdirs.Add(vDirName, (className.Replace("Service""VirtualDir")));
 78       newVDir.Properties["Path"][0= physicalPath;
 79       newVDir.Properties["AccessScript"][0= true;
 80       // These properties are necessary for an application to be created.
 81       newVDir.Properties["AppFriendlyName"][0= vDirName;
 82       newVDir.Properties["AppIsolated"][0= "1";
 83       newVDir.Properties["AppRoot"][0= "/LM" + metabasePath.Substring(metabasePath.IndexOf("/", ("IIS://".Length)));
 84 
 85       newVDir.CommitChanges();
 86 
 87       Console.WriteLine(" Done.");
 88     }
 89     else
 90       Console.WriteLine(" Failed. A virtual directory can only be created in a site or virtual directory node.");
 91   }
 92   catch (Exception ex)
 93   {
 94     Console.WriteLine("Failed in CreateVDir with the following exception: \n{0}", ex.Message);
 95   }
 96 }
 97 
 98 
 99 
100 static void AssignVDirToAppPool(string metabasePath, string appPoolName)
101 {
102   //  metabasePath is of the form "IIS://<servername>/W3SVC/<siteID>/Root[/<vDir>]"
103   //    for example "IIS://localhost/W3SVC/1/Root/MyVDir" 
104   //  appPoolName is of the form "<name>", for example, "MyAppPool"
105   Console.WriteLine("\nAssigning application {0} to the application pool named {1}:", metabasePath, appPoolName);
106 
107   try
108   {
109     DirectoryEntry vDir = new DirectoryEntry(metabasePath);
110     string className = vDir.SchemaClassName.ToString();
111     if (className.EndsWith("VirtualDir"))
112     {
113       object[] param = { 0, appPoolName, true };
114       vDir.Invoke("AppCreate3", param);
115       vDir.Properties["AppIsolated"][0= "2";
116       Console.WriteLine(" Done.");
117     }
118     else
119       Console.WriteLine(" Failed in AssignVDirToAppPool; only virtual directories can be assigned to application pools");
120   }
121   catch (Exception ex)
122   {
123     Console.WriteLine("Failed in AssignVDirToAppPool with the following exception: \n{0}", ex.Message);
124   }
125 }
126 
127 
128 
129   }
130 }
131   
132  
133