Microsoft.Web.Administration之iis,杂抄,,


iis{
站点[
应用程序 [
{
虚拟目录 [
路径1,
路径2,
],
线程池名,
}
]
],
线程池[
池1,
池2
]
}

http响应标头
ip地址和域限制
isapi筛选器
mime类型
处理程序映射
错误页
模块
默认文档
目录浏览
请求筛选
日志
身份验证

 

 

EnabledProtocols

site1.ApplicationDefaults.RawAttributes

path
applicationPool
enabledProtocols,http
serviceAutoStartEnabled,False
serviceAutoStartProvider,
proloadEnabled,False

site1.ApplicationDefaults.Configuration.ConfigurationPathToEdit
"MACHINE/WEBROOT/APPHOST"
site1.ApplicationDefaults.Configuration._configPathToEdit
"MACHINE/WEBROOT/APPHOST"

new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, string>(new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.ConfigurationElement>(site1.ChildElements._elements).Items[1].RawAttributes).Items[1]
最大连接数,
new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, string>(new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.ConfigurationElement>(site1.ChildElements._elements).Items[1].RawAttributes).Items[2]
超时

日志
new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.ConfigurationElement>(site1.ChildElements._elements).Items[2].Attributes._attributes
Name = "logExtFileFlags"
Name = "customLogPluginClsid"
Name = "logFormat"
Name = "logTargetW3C"
Name = "directory"
Name = "period"
Name = "truncateSize"
Name = "localTimeRollover"
Name = "enabled"
Name = "logSiteId"
Name = "flushByEntryCountW3CLog"
Name = "maxLogLineLength"

new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.ConfigurationElement>(site1.ChildElements._elements).Items[2].RawAttributes
{[logExtFileFlags, 2478031]}
{[customLogPluginClsid, ]}
{[logFormat, 2]}
{[logTargetW3C, 1]}
{[directory, C:\inetpub\logs\LogFiles]}
{[period, 1]}
{[truncateSize, 20971520]}
{[localTimeRollover, False]}
{[enabled, True]}
{[logSiteId, True]}
{[flushByEntryCountW3CLog, 0]}
{[maxLogLineLength, 65536]}


new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.ConfigurationElement>(site1.ChildElements._elements).Items[3].Attributes._attributes
Name = "enabled"
Name = "directory"
Name = "maxLogFiles"
Name = "maxLogFileSizeKB"
Name = "customActionsEnabled"

new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.ConfigurationElement>(site1.ChildElements._elements).Items[3].RawAttributes
{[enabled, False]}
{[directory, C:\inetpub\logs\FailedReqLogFiles]}
{[maxLogFiles, 50]}
{[maxLogFileSizeKB, 1024]}
{[customActionsEnabled, False]}

site1.Limits.ConnectionTimeout
Days 0 int
Hours 0 int
Milliseconds 0 int
Minutes 2 int
Seconds 0 int
Ticks 1200000000 long
TotalDays 0.0013888888888888887 double
TotalHours 0.033333333333333333 double
TotalMilliseconds 120000 double
TotalMinutes 2 double
TotalSeconds 120 double


site1.LogFile.Attributes._attributes
Name = "logExtFileFlags"
Name = "customLogPluginClsid"
Name = "logFormat"
Name = "logTargetW3C"
Name = "directory"
Name = "period"
Name = "truncateSize"
Name = "localTimeRollover"
Name = "enabled"
Name = "logSiteId"
Name = "flushByEntryCountW3CLog"
Name = "maxLogLineLength"

site1.LogFile.LogExtFileFlags
Date | Time | ClientIP | UserName | ServerIP | Method | UriStem | UriQuery | HttpStatus | Win32Status | TimeTaken | ServerPort | UserAgent | Referer | HttpSubStatus


new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, string>(site1.RawAttributes).Items[0]
{[name, site102]}
{[id, 8]}
{[serverAutoStart, True]}
{[state, 1]}


ServerAutoStart
State
Name

site1.VirtualDirectoryDefaults.Attributes._attributes

Name = "path"
Name = "physicalPath"
Name = "userName"
Name = "password"
Name = "logonMethod"
Name = "allowSubDirConfig"

site1.VirtualDirectoryDefaults.RawAttributes
{[path, ]}
{[physicalPath, ]}
"physicalPath"
""

{[userName, ]}
{[password, ]}
{[logonMethod, 3]}
{[allowSubDirConfig, True]}

 

线程池,对象,版本号,.

 


3) 站点权限设置


复制代码
1 Configuration config = serverManager.GetApplicationHostConfiguration();
2 ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication",sitename );
3 anonymousAuthenticationSection["enabled"] = true;
4 anonymousAuthenticationSection["userName"] = @"IUSR_" + this.txt_No.Text.ToString();
5 anonymousAuthenticationSection["password"] = @"" + this.txt_password.Text.ToString();
6 serverManager.CommitChanges();

 


1) 显示站点列表


复制代码
1 void getListOfIIS(){
2 this.listBox1.Items.Clear();
3 string StateStr = "";
4 for(int i=0; i<IISManager.Sites.Count;i++){
5
6 switch(IISManager.Sites[i].State){
7 case ObjectState.Started:{
8 StateStr = "正常";break;
9 }
10 case ObjectState.Starting:{
11 StateStr = "正在启动"; break;
12 }
13 case ObjectState.Stopping:{
14 StateStr = "正在关闭"; break;
15 }
16 case ObjectState.Stopped:{
17 StateStr = "关闭";break;
18 }
19 }
20 this.listBox1.Items.Add(IISManager.Sites[i].Name+"【"+StateStr+"】");
21 }
22 }
复制代码
2) 创建站点、绑定域名


复制代码
1 static void Main(string[] args)
2 {
3 ServerManager serverManager = new ServerManager();
4 Site site = IISManager.Sites.Add("site name", "http", "*:80:"+siteUrl, sitePath);
5 mySite.ServerAutoStart = true;
6 serverManager.CommitChanges();
7 }
复制代码
3) 站点权限设置


复制代码
1 Configuration config = serverManager.GetApplicationHostConfiguration();
2 ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication",sitename );
3 anonymousAuthenticationSection["enabled"] = true;
4 anonymousAuthenticationSection["userName"] = @"IUSR_" + this.txt_No.Text.ToString();
5 anonymousAuthenticationSection["password"] = @"" + this.txt_password.Text.ToString();
6 serverManager.CommitChanges();
复制代码
4) 创建应用池


复制代码
1 ApplicationPool newPool = IISManager.ApplicationPools[appoolname];
2 if (newPool == null)
3 {
4 IISManager.ApplicationPools.Add(appoolname);
5 newPool = IISManager.ApplicationPools[appoolname];
6 newPool.Name =appoolname;
7 newPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
8 newPool.ManagedRuntimeVersion = "v2.0";
9 }
复制代码
5) 站点应用池绑定


1 site.Applications["/"].ApplicationPoolName = appoolName //此appoolname就是新的的引用池
6) 追加域名


复制代码
private void BindURL(string UserName)
{
string str = this.IISManager.Sites[UserName].Bindings[0].Host.Split(new char[]{'.'})[0];
string bindingInformation = "*:80:" + str + "." + this.txt_addUrl.Text;
this.IISManager.Sites[UserName].Bindings.Add(bindingInformation, "http");
this.IISManager.CommitChanges();
}
复制代码
7) 删除站点、删除应用池


1 this.IISManager.Sites[sitename)].Applications.Remove(this.IISManager.Sites[sitename].Applications[0]);
2 this.IISManager.Sites.Remove(this.IISManager.Sites[sitename]);
3 this.IISManager.ApplicationPools.Remove(this.IISManager.ApplicationPools[appoolname]);
4 this.IISManager.CommitChanges();
5 this.txt_log.AppendText(sitename+ "站点删除成功\r\n!");

三、动态运行库类  

复制代码
1 ServerManager ms = new ServerManager();
2 foreach(WorkerProcess wp in ms.WorkerProcesses){
3 Console.WriteLine(wp.AppPoolName+ " " +wp.ProcessGuid+" "+wp.Schema);
4 foreach(Request request In wp.GetRequests(0)){
5 Console.WriteLine(" request:"+request.Url);
6 }
7 }
8
复制代码
用户访问控制(UAC)可能会干扰正常工作,如果没有得到结果,那么首先确认是否有管理员的权限,这样就避免UAC阻止的问题,查看所有处于运行的状态的请求,注意GetRequest(0)中参数0代表

也没的总运行时间 。

 

四、访问远程服务器

复制代码
1 try{
2 ServerManager ms = ServerManager.OpenRemote("116.254.199.39");
3 for(int i=0; i<ms.Sites.Count;i++){
4 Console.WriteLine(ms.Sites[i].Name);
5 }
6 }catch(Exception ex){
7 Console.WriteLine(ex.Message);
8 }finally{
9 Console.WriteLine("成功");
10 }
复制代码
连接一台远程IIS 服务器,只需要简单的调用SerManager.OpenRemote。 可以在OpenRemotede的ServerName中使用IP地址主机名或者域名。

五、直接编辑属性和元素
这里需要先补充下IIS 配置文件层次结构

 

 

可以使用ServerManager基类查看、创建、更新或者删除配置文件中的任何属性和元素。我们可以编辑任何IIS配置文件,包括appclicationHost.config、administration.cconfig、redirection.config, 已经所有网站应用程序配置

不同的配置文件对应着不同的 对象

复制代码
1 ServerManager ms = new ServerManager();
2 //获取 applicationHost.conf
3 Configuration config = ms.GetApplicationHostConfiguration;
4
5 //获取特定网站的web.config配置文件
6 Configuration config = ms.GetWebConfiguration("site1");
7
8 // 获取一个应用程序的 配置文件
9 Configuration config = ms.GetWebConfiguration("site1","/App1");
10
11 //获取一个特定的location标记
12 ConfigurationSection section= config.GetSection("system.webServer/defaultDocumnet");
13
14 //获取site1 web.config 配置文件中属于启动的状态属性
15 ConfigurationAttribute enabled = section.Attributes("enabled");
16 Console.WriteLine(enabled.Value);
17
18 //获取网站默认文档
19 ConfigurationElementCollection filescollection = section.GetCollection("files");
20 foreach(ConfigurationElement el in filescollection){
21 Console.WriteLine(el.Attributes("value"));
22 }
23
24
复制代码




Microsoft.Web.Administration.ServerManager启用IIS的ISAPI
复制代码
const string isAPI_partialPath = @"v4.0.30319\aspnet_isapi.dll";
static void Main(string[] args)
{
ServerManager svrMgr = new ServerManager();
Configuration config = svrMgr.GetApplicationHostConfiguration();


ConfigurationSection section = config.GetSection("system.webServer/security/isapiCgiRestriction");


foreach (ConfigurationElement item in section.GetCollection())//这里是GetCollection(),不是ChildElement。诸如<add />的标签是集合不是它的子元素
{
if (item.Attributes.Count > 0 && item.Attributes["path"].Value != null && item.Attributes["path"].Value.ToString().EndsWith(isAPI_partialPath))
{
item.Attributes["allowed"].Value = true;
}
}

svrMgr.CommitChanges();
}

解决方法 1:
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();

解决方法 2:
这里是一个 帖子相关 检索站点 id。

这里的一些代码,可能会为您的工作:

using System.DirectoryServices;
using System;

public class IISAdmin
{
public static void GetWebsiteID(string websiteName)
{
DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");

foreach(DirectoryEntry de in w3svc.Children)
{
if(de.SchemaClassName == "IIsWebServer" && de.Properties["ServerComment"][0].ToString() == websiteName)
{
Console.Write(de.Name);
}

}

}
public static void Main()
{
GetWebsiteID("Default Web Site");
}


解决方法 3:
您正在寻找 ServerManager (Microsoft.Web.Administration) 提供的读取和写入访问,IIS 7.0 配置系统。

循环访问 Microsoft.Web.Administration.SiteCollection、 获取对您的网站使用站点对象的引用,并读取名称属性的值。

// Snippet
using (ServerManager serverManager = new ServerManager()) {

var sites = serverManager.Sites;
foreach (Site site in sites) {
Console.WriteLine(site.Name); // This will return the WebSite name
}
您还可以使用 LINQ 查询 ServerManager.Sites 集合 (请参见下面的示例)

// Start all stopped WebSites using the power of Linq :)
var sites = (from site in serverManager.Sites
where site.State == ObjectState.Stopped
orderby site.Name
select site);

foreach (Site site in sites) {
site.Start();
}
注 : Microsoft.Web.Administration 仅 IIS7的工作。

IIS6,您可以使用 ADSI 和 WMI 这样做,但我建议你去为 WMI ADSI 比快。如果使用 WMI,我们看看 WMI 代码创建者 1.0 (免费 / 发达的 Microsoft)。它将为您生成的代码。

禾田


解决方法 4:
这篇文章为您提供了了解如何,您可以检索 IIS 信息并创建网站/虚拟目录。

创建一个网站,以编程方式使用 C# 应用程序池

解决方法 5:
您需要先做 ServerManager.OpenRemote("serverName"),当连接到远程服务器。

它的基本做法这样的

using (ServerManager srvMgr = ServerManager.OpenRemote("serverName"))
{

}


ServerManager是IIS7.0 API所提供的最重要物件,ServerManager這個物件中,主要包含三個大項屬性:ApplicationPools、Sites、WorkerProcesses。

ApplicationPools:代表的是應用程式集區的設定與狀態。

Sites:代表的是站台的設定與狀態。

WorkerProcesses:代表的是w3wp的狀態。

 


『建立虛擬目錄』

//取得應用程式
Application tApp = tServerManager.Sites["NewSite"].Applications["/Sales"];
//新增虛擬目錄VDir,對應到實體路徑為D:\\MyVDir
tApp.VirtualDirectories.Add("/VDir", "D:\\MyVDir");
tServerManager.CommitChanges();

 


『建立應用程式』

//在NewSite站台下加入名稱為Sales的應用程式,對應的實體路徑為D:\\MyApp
tServerManager.Sites["NewSite"].Applications.Add("/Sales", "D:\\MyApp");
tServerManager.CommitChanges();

 

 

 


Microsoft.Web.Administration.ServerManager sm = new Microsoft.Web.Administration.ServerManager();

System.Console.WriteLine("应用程序池默认设置:");
System.Console.WriteLine("\t常规:");
System.Console.WriteLine("\t\t.NET Framework 版本:{0}", sm.ApplicationPoolDefaults.ManagedRuntimeVersion);
System.Console.WriteLine("\t\t队列长度:{0}", sm.ApplicationPoolDefaults.QueueLength);
System.Console.WriteLine("\t\t托管管道模式:{0}", sm.ApplicationPoolDefaults.ManagedPipelineMode.ToString());
System.Console.WriteLine("\t\t自动启动:{0}", sm.ApplicationPoolDefaults.AutoStart);

System.Console.WriteLine("\tCPU:");
System.Console.WriteLine("\t\t处理器关联掩码:{0}", sm.ApplicationPoolDefaults.Cpu.SmpProcessorAffinityMask);
System.Console.WriteLine("\t\t限制:{0}", sm.ApplicationPoolDefaults.Cpu.Limit);
System.Console.WriteLine("\t\t限制操作:{0}", sm.ApplicationPoolDefaults.Cpu.Action.ToString());
System.Console.WriteLine("\t\t限制间隔(分钟):{0}", sm.ApplicationPoolDefaults.Cpu.ResetInterval.TotalMinutes);
System.Console.WriteLine("\t\t已启用处理器关联:{0}", sm.ApplicationPoolDefaults.Cpu.SmpAffinitized);

System.Console.WriteLine("\t回收:");
System.Console.WriteLine("\t\t发生配置更改时禁止回收:{0}", sm.ApplicationPoolDefaults.Recycling.DisallowRotationOnConfigChange);
System.Console.WriteLine("\t\t固定时间间隔(分钟):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Time.TotalMinutes);
System.Console.WriteLine("\t\t禁用重叠回收:{0}", sm.ApplicationPoolDefaults.Recycling.DisallowOverlappingRotation);
System.Console.WriteLine("\t\t请求限制:{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Requests);
System.Console.WriteLine("\t\t虚拟内存限制(KB):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Memory);
System.Console.WriteLine("\t\t专用内存限制(KB):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.PrivateMemory);
System.Console.WriteLine("\t\t特定时间:{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Schedule.ToString());
System.Console.WriteLine("\t\t生成回收事件日志条目:{0}", sm.ApplicationPoolDefaults.Recycling.LogEventOnRecycle.ToString());

System.Console.WriteLine("\t进程孤立:");
System.Console.WriteLine("\t\t可执行文件:{0}", sm.ApplicationPoolDefaults.Failure.OrphanActionExe);
System.Console.WriteLine("\t\t可执行文件参数:{0}", sm.ApplicationPoolDefaults.Failure.OrphanActionParams);
System.Console.WriteLine("\t\t已启用:{0}", sm.ApplicationPoolDefaults.Failure.OrphanWorkerProcess);

System.Console.WriteLine("\t进程模型:");
System.Console.WriteLine("\t\tPing 间隔(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.PingInterval.TotalSeconds);
System.Console.WriteLine("\t\tPing 最大响应时间(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.PingResponseTime.TotalSeconds);
System.Console.WriteLine("\t\t标识:{0}", sm.ApplicationPoolDefaults.ProcessModel.IdentityType);
System.Console.WriteLine("\t\t用户名:{0}", sm.ApplicationPoolDefaults.ProcessModel.UserName);
System.Console.WriteLine("\t\t密码:{0}", sm.ApplicationPoolDefaults.ProcessModel.Password);
System.Console.WriteLine("\t\t关闭时间限制(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.ShutdownTimeLimit.TotalSeconds);
System.Console.WriteLine("\t\t加载用户配置文件:{0}", sm.ApplicationPoolDefaults.ProcessModel.LoadUserProfile);
System.Console.WriteLine("\t\t启动时间限制(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.StartupTimeLimit.TotalSeconds);
System.Console.WriteLine("\t\t允许 Ping:{0}", sm.ApplicationPoolDefaults.ProcessModel.PingingEnabled);
System.Console.WriteLine("\t\t闲置超时(分钟):{0}", sm.ApplicationPoolDefaults.ProcessModel.IdleTimeout.TotalMinutes);
System.Console.WriteLine("\t\t最大工作进程数:{0}", sm.ApplicationPoolDefaults.ProcessModel.MaxProcesses);

System.Console.WriteLine("\t快速故障防护:");
System.Console.WriteLine("\t\t“服务不可用”响应类型:{0}", sm.ApplicationPoolDefaults.Failure.LoadBalancerCapabilities.ToString());
System.Console.WriteLine("\t\t故障间隔(分钟):{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtectionInterval.TotalMinutes);
System.Console.WriteLine("\t\t关闭可执行文件:{0}", sm.ApplicationPoolDefaults.Failure.AutoShutdownExe);
System.Console.WriteLine("\t\t关闭可执行文件参数:{0}", sm.ApplicationPoolDefaults.Failure.AutoShutdownParams);
System.Console.WriteLine("\t\t已启用:{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtection);
System.Console.WriteLine("\t\t最大故障数:{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtectionMaxCrashes);
System.Console.WriteLine("\t\t允许32位应用程序运行在64位 Windows 上:{0}", sm.ApplicationPoolDefaults.Enable32BitAppOnWin64);

System.Console.WriteLine();
System.Console.WriteLine("网站默认设置:");
System.Console.WriteLine("\t常规:");
System.Console.WriteLine("\t\t物理路径凭据:UserName={0}, Password={1}", sm.VirtualDirectoryDefaults.UserName, sm.VirtualDirectoryDefaults.Password);
System.Console.WriteLine("\t\t物理路径凭据登录类型:{0}", sm.VirtualDirectoryDefaults.LogonMethod.ToString());
System.Console.WriteLine("\t\t应用程序池:{0}", sm.ApplicationDefaults.ApplicationPoolName);
System.Console.WriteLine("\t\t自动启动:{0}", sm.SiteDefaults.ServerAutoStart);
System.Console.WriteLine("\t行为:");
System.Console.WriteLine("\t\t连接限制:");
System.Console.WriteLine("\t\t\t连接超时(秒):{0}", sm.SiteDefaults.Limits.ConnectionTimeout.TotalSeconds);
System.Console.WriteLine("\t\t\t最大并发连接数:{0}", sm.SiteDefaults.Limits.MaxConnections);
System.Console.WriteLine("\t\t\t最大带宽(字节/秒):{0}", sm.SiteDefaults.Limits.MaxBandwidth);
System.Console.WriteLine("\t\t失败请求跟踪:");
System.Console.WriteLine("\t\t\t跟踪文件的最大数量:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.MaxLogFiles);
System.Console.WriteLine("\t\t\t目录:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.Directory);
System.Console.WriteLine("\t\t\t已启用:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.Enabled);
System.Console.WriteLine("\t\t已启用的协议:{0}", sm.ApplicationDefaults.EnabledProtocols);

foreach (var s in sm.Sites)//遍历网站
{
System.Console.WriteLine();
System.Console.WriteLine("模式名:{0}", s.Schema.Name);
System.Console.WriteLine("编号:{0}", s.Id);
System.Console.WriteLine("网站名称:{0}", s.Name);
System.Console.WriteLine("物理路径:{0}", s.Applications["/"].VirtualDirectories["/"].PhysicalPath);
System.Console.WriteLine("物理路径凭据:{0}", s.Methods.ToString());
System.Console.WriteLine("应用程序池:{0}", s.Applications["/"].ApplicationPoolName);
System.Console.WriteLine("已启用的协议:{0}", s.Applications["/"].EnabledProtocols);
System.Console.WriteLine("自动启动:{0}", s.ServerAutoStart);
System.Console.WriteLine("运行状态:{0}", s.State.ToString());

System.Console.WriteLine("网站绑定:");
foreach (var tmp in s.Bindings)
{
System.Console.WriteLine("\t类型:{0}", tmp.Protocol);
System.Console.WriteLine("\tIP 地址:{0}", tmp.EndPoint.Address.ToString());
System.Console.WriteLine("\t端口:{0}", tmp.EndPoint.Port.ToString());
System.Console.WriteLine("\t主机名:{0}", tmp.Host);
//System.Console.WriteLine(tmp.BindingInformation);
//System.Console.WriteLine(tmp.CertificateStoreName);
//System.Console.WriteLine(tmp.IsIPPortHostBinding);
//System.Console.WriteLine(tmp.IsLocallyStored);
//System.Console.WriteLine(tmp.UseDsMapper);
}

System.Console.WriteLine("连接限制:");
System.Console.WriteLine("\t连接超时(秒):{0}", s.Limits.ConnectionTimeout.TotalSeconds);
System.Console.WriteLine("\t最大并发连接数:{0}", s.Limits.MaxConnections);
System.Console.WriteLine("\t最大带宽(字节/秒):{0}", s.Limits.MaxBandwidth);

System.Console.WriteLine("失败请求跟踪:");
System.Console.WriteLine("\t跟踪文件的最大数量:{0}", s.TraceFailedRequestsLogging.MaxLogFiles);
System.Console.WriteLine("\t目录:{0}", s.TraceFailedRequestsLogging.Directory);
System.Console.WriteLine("\t已启用:{0}", s.TraceFailedRequestsLogging.Enabled);

System.Console.WriteLine("日志:");
//System.Console.WriteLine("\t启用日志服务:{0}", s.LogFile.Enabled);
System.Console.WriteLine("\t格式:{0}", s.LogFile.LogFormat.ToString());
System.Console.WriteLine("\t目录:{0}", s.LogFile.Directory);
System.Console.WriteLine("\t文件包含字段:{0}", s.LogFile.LogExtFileFlags.ToString());
System.Console.WriteLine("\t计划:{0}", s.LogFile.Period.ToString());
System.Console.WriteLine("\t最大文件大小(字节):{0}", s.LogFile.TruncateSize);
System.Console.WriteLine("\t使用本地时间进行文件命名和滚动更新:{0}", s.LogFile.LocalTimeRollover);

System.Console.WriteLine("----应用程序的默认应用程序池:{0}", s.ApplicationDefaults.ApplicationPoolName);
System.Console.WriteLine("----应用程序的默认已启用的协议:{0}", s.ApplicationDefaults.EnabledProtocols);
//System.Console.WriteLine("----应用程序的默认物理路径凭据:{0}", s.ApplicationDefaults.Methods.ToString());
//System.Console.WriteLine("----虚拟目录的默认物理路径凭据:{0}", s.VirtualDirectoryDefaults.Methods.ToString());
System.Console.WriteLine("----虚拟目录的默认物理路径凭据登录类型:{0}", s.VirtualDirectoryDefaults.LogonMethod.ToString());
System.Console.WriteLine("----虚拟目录的默认用户名:{0}", s.VirtualDirectoryDefaults.UserName);
System.Console.WriteLine("----虚拟目录的默认用户密码:{0}", s.VirtualDirectoryDefaults.Password);
System.Console.WriteLine("应用程序 列表:");
foreach (var tmp in s.Applications)
{
if (tmp.Path != "/")
{
System.Console.WriteLine("\t模式名:{0}", tmp.Schema.Name);
System.Console.WriteLine("\t虚拟路径:{0}", tmp.Path);
System.Console.WriteLine("\t物理路径:{0}", tmp.VirtualDirectories["/"].PhysicalPath);
//System.Console.WriteLine("\t物理路径凭据:{0}", tmp.Methods.ToString());
System.Console.WriteLine("\t应用程序池:{0}", tmp.ApplicationPoolName);
System.Console.WriteLine("\t已启用的协议:{0}", tmp.EnabledProtocols);
}
System.Console.WriteLine("\t虚拟目录 列表:");
foreach (var tmp2 in tmp.VirtualDirectories)
{
if (tmp2.Path != "/")
{
System.Console.WriteLine("\t\t模式名:{0}", tmp2.Schema.Name);
System.Console.WriteLine("\t\t虚拟路径:{0}", tmp2.Path);
System.Console.WriteLine("\t\t物理路径:{0}", tmp2.PhysicalPath);
//System.Console.WriteLine("\t\t物理路径凭据:{0}", tmp2.Methods.ToString());
System.Console.WriteLine("\t\t物理路径凭据登录类型:{0}", tmp2.LogonMethod.ToString());
}
}
}
}


- SectionGroups Count = 3 Microsoft.Web.Administration.SectionGroupCollection

 


IsIPPortHostBinding true bool
IsLocallyStored false bool
new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.Binding>(site1.Bindings._elements).Items[0].IsIPPortHostBinding
Protocol "http" string

 

new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.VirtualDirectory>(new System.Collections.Generic.Mscorlib_CollectionDebugView<Microsoft.Web.Administration.Application>(site1.Applications._elements).Items[0].VirtualDirectories._elements).Items[0].PhysicalPath
PhysicalPath "F:\\controlWebIIs7\\web100" string

Path "/" string

ElementTagName "virtualDirectory" string

 

+ [0] Name = "path" Microsoft.Web.Administration.ConfigurationAttribute
+ [1] Name = "physicalPath" Microsoft.Web.Administration.ConfigurationAttribute
+ [2] Name = "userName" Microsoft.Web.Administration.ConfigurationAttribute
+ [3] Name = "password" Microsoft.Web.Administration.ConfigurationAttribute
+ [4] Name = "logonMethod" Microsoft.Web.Administration.ConfigurationAttribute
+ [5] Name = "allowSubDirConfig" Microsoft.Web.Administration.ConfigurationAttribute


site1.Application,VirtualDirectories

 

https://msdn.microsoft.com/zh-tw/library/microsoft.web.administration.virtualdirectorydefaults.username(v=vs.85).aspx

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
public class AdministrationApplicationVirtualDirectoryDefaults
{
...


// Creates a new application, sets the virtual directory
// defaults, creates two new virtual directories, and then
// displays the new virtual directory values.
public void SetVirtualDirectoryDefaults()
{
ServerManager manager = new ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];

// Set up the defaults for the default application of the
// default Web site.
Application app = defaultSite.Applications.Add(
"/JohnDoe", @"C:\inetpub\wwwroot\john");

app.VirtualDirectoryDefaults.LogonMethod =
AuthenticationLogonMethod.ClearText;
app.VirtualDirectoryDefaults.UserName = @"NorthWest\JohnDoe";
app.VirtualDirectoryDefaults.Password = @"kB56^j83!T";

// Add two virtual directories.
app.VirtualDirectories.Add(
"/blogs" , @"\\FileServer\c$\blog_content\");
app.VirtualDirectories.Add(
"/photos", @"\\FileServer\c$\photo_content\");
manager.CommitChanges();

// Read the updated configuration.
app = defaultSite.Applications["/JohnDoe"];

foreach (VirtualDirectory vdir in app.VirtualDirectories)
{
Console.WriteLine("Virtual Directory Found: {0}", vdir.Path);
Console.WriteLine(" |-Logon Method : {0}", vdir.LogonMethod);
Console.WriteLine(" |-Username : {0}", vdir.UserName);
Console.WriteLine(" +-Password : {0}", vdir.Password);
}
}
...

}
}

 

 


site1.Schema.ChildElementSchemas._schemas
+ [0] Name = "bindings" Microsoft.Web.Administration.ConfigurationElementSchema
+ [1] Name = "limits" Microsoft.Web.Administration.ConfigurationElementSchema
+ [2] Name = "logFile" Microsoft.Web.Administration.ConfigurationElementSchema
+ [3] Name = "traceFailedRequestsLogging" Microsoft.Web.Administration.ConfigurationElementSchema
+ [4] Name = "hsts" Microsoft.Web.Administration.ConfigurationElementSchema
+ [5] Name = "applicationDefaults" Microsoft.Web.Administration.ConfigurationElementSchema
+ [6] Name = "virtualDirectoryDefaults" Microsoft.Web.Administration.ConfigurationElementSchema
+ [7] Name = "ftpServer" Microsoft.Web.Administration.ConfigurationElementSchema

posted @ 2018-06-15 11:43  以函  阅读(274)  评论(0编辑  收藏  举报