IIS Manager 不同方式创建比较
来源:互联网 发布:淘宝仓库出货流程 编辑:程序博客网 时间:2024/05/16 09:07
可以有几种方式创建IIS,请根据具体情况选择不同的方法。
http://blog.crowe.co.nz/archive/2006/07/04/663.aspx
1 .The IIS ADSI Provider
The IIS ADSI provider exposes COM Automation objects that you can use within command-line scripts, ASP pages, or custom applications to change IIS configuration values stored in the IIS metabase. IIS ADSI objects can be accessed and manipulated by any language that supports automation, such as Microsoft® Visual Basic® Scripting Edition (VBScript), Microsoft JScript®, Perl, Microsoft Active Server Pages (ASP), Visual Basic, Java, or Microsoft C++.
这种方法通用,不必担心不同的IIS 版本。GOOD
2. The IIS WMI Provider
Windows Management Instrumentation (WMI) is a technology that allows administrators to programmatically manage and configure the Windows operating system and Windows applications. Beginning with IIS 6.0, IIS includes a WMI provider that exposes programming interfaces that can be used to query and configure the IIS metabase.
IIS6.0才可以使用,不建议使用。BAD
3. The Microsoft.Web.Administration namespace in IIS 7
This is a new .NET managed namespace that will allow you to talk to IIS 7 and configure all aspects of the server. This API is designed to be simple to code against in an “intellisense-driven” sort of way. At the root level a class called ServerManager exposes all the functionality you will need. At this time it appears that this will not be able to be used from Windows XP but by the time Vista & Windows Server are released this may have been ported to run on a Windows XP client.
IIS7.0的新方法。
For more details on these technologies see the following resources:
* Active Directory Service Interfaces Overview
http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/adsilinks.asp
* WMI - Windows Management Instrumentation
http://www.microsoft.com/whdc/system/pnppwr/wmi/default.mspx
* Administering IIS Programmatically (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/9041b0a5-c314-46d9-8f56-01506687f357.mspx
* Pre-release documentation on Microsoft.Web.Administration
http://windowssdk.msdn.microsoft.com/en-us/library/microsoft.web.administration.aspx
1. ADSI:
public static bool DeleteWebSite(string targetsite,string serverName, string targetDirectory)
{
DirectoryEntry deRoot = new DirectoryEntry("IIS://" + serverName + @"/" + targetsite);
try
{
deRoot.RefreshCache();
DirectoryEntry folderRoot = deRoot.Children.Find("Root", "IIsWebVirtualDir");
DirectoryEntry newVirDir = folderRoot.Children.Find(targetDirectory, "IIsWebVirtualDir");
folderRoot.Children.Remove(newVirDir);
folderRoot.CommitChanges();
deRoot.CommitChanges();
folderRoot.Close();
deRoot.Close();
}
catch
{
return false;
}
return true;
}
public static bool UpdateWebSite(string targetsite, string serverName, string targetVDir, string targetDirectory, string friendlyName)
{
DirectoryEntry deRoot = new DirectoryEntry("IIS://" + serverName + @"/" + targetsite);
try
{
deRoot.RefreshCache();
DirectoryEntry folderRoot = deRoot.Children.Find("Root", "IIsWebVirtualDir");
DirectoryEntry deNewVDir = folderRoot.Children.Find(targetVDir, "IIsWebVirtualDir");
if (targetDirectory.EndsWith("//"))
{
targetDirectory = targetDirectory.Substring(0, targetDirectory.Length - 1);
}
deNewVDir.Properties["Path"].Insert(0, targetDirectory);
deNewVDir.Properties["AccessExecute"][0] = false;
deNewVDir.Properties["AccessRead"][0] = true;
deNewVDir.Properties["AccessWrite"][0] = true;
deNewVDir.Properties["ContentIndexed"][0] = true;
deNewVDir.Properties["DefaultDoc"][0] = "Default.aspx,Login.aspx";
deNewVDir.Properties["AppFriendlyName"][0] = friendlyName;
deNewVDir.Properties["AppIsolated"][0] = 2;
deNewVDir.Properties["AccessScript"][0] = true;
deNewVDir.Properties["DontLog"][0] = true;
deNewVDir.CommitChanges();
deRoot.CommitChanges();
// Save Changes
deNewVDir.Close();
deRoot.Close();
}
catch
{
return false;
}
return true;
}
public static bool CreateWebSite(string targetSite, string serverName, string targetVDir, string targetDirectory, string friendlyName)
{
try
{
DirectoryEntry deRoot = new DirectoryEntry("IIS://" + serverName + @"/" + targetSite);
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add(targetVDir, "IIsWebVirtualDir");
if (targetDirectory.EndsWith("//"))
{
targetDirectory = targetDirectory.Substring(0, targetDirectory.Length - 1);
}
deNewVDir.Properties["Path"].Insert(0, targetDirectory);
deNewVDir.Properties["AccessExecute"][0] = false;
deNewVDir.Properties["AccessRead"][0] = true;
deNewVDir.Properties["AccessWrite"][0] = true;
deNewVDir.Properties["ContentIndexed"][0] = true;
deNewVDir.Properties["DefaultDoc"][0] = "Default.aspx,Login.aspx";
deNewVDir.Properties["AppFriendlyName"][0] = friendlyName;
deNewVDir.Properties["AppIsolated"][0] = 2;
deNewVDir.Properties["AccessScript"][0] = true;
deNewVDir.Properties["DontLog"][0] = true;
deNewVDir.CommitChanges();
deRoot.CommitChanges();
// Create a Application
deNewVDir.Invoke("AppCreate", true);
// Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
}
catch
{
return false;
}
return true;
}
2.Using System.Managment and WMI
ManagementScope oms = new ManagementScope(@"//./root/MicrosoftIISv2"); oms.Connect(); ObjectQuery oQuery = new ObjectQuery("select * from IISWebServerSetting"); ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oms, oQuery); foreach (ManagementObject oreturn in oSearcher.Get()) { Console.WriteLine(oreturn["ServerComment"]+" ("+oreturn["Name"]+")"); } Console.Read();
3. Using Microsoft.Web.Administration ( II7 Only )
ServerManager iisManager = new ServerManager(); Console.WriteLine("Display IIS Sites in IIS 7"); Console.WriteLine("".PadLeft(40,'-')); foreach(Site site in iisManager.Sites) { Console.WriteLine("{0} {1}", site.Id.ToString().PadRight(12), site.Name); } Console.Read();
- IIS Manager 不同方式创建比较
- Bean不同配置方式比较
- IIS中发布网站的不同方式
- ArrayList列表不同遍历方式性能比较
- Python+不同的数据存储方式比较
- Spring-不同配置方式的比较
- Spring学习,Bean不同配置方式比较
- IIS集成验证方式下的不同验证模式
- IIS集成验证方式下的不同验证模式
- IIS集成验证方式下的不同验证模式
- IIS集成验证方式下的不同验证模式
- 创建IRP的四种不同方式
- 创建IRP的四种不同方式
- 不同Bean创建方式以及对应配置
- Java字符串不同创建方式的理解
- hibernate创建sessionFactory的不同方式
- 创建线程有几种不同的方式?
- 几种不同的log4j创建方式
- Using Azure blob storage in silverlight
- WebSetup/Windows Setup Project Summary
- [翻译]jQuery 选择器的使用
- 二分查找法
- 编号自增长(基于SSH)
- IIS Manager 不同方式创建比较
- Oracle笔记——转贴
- 意气帮转:贵州都匀征集目击者:又一南京老太太
- SQL中的DDL,DML,DCL语言
- sql122n
- 教你使用XNA Game Studio 3.1+C#开发游戏
- VB.Net程序设计:小代码段图片被锁住问题
- JVM内存段分配,Java垃圾回收调优,Heap设定,Jvm内存回收算法
- TcpListener/TcpClient/UdpClient 的区别及联系