IIS 7管理API——使用 Microsoft.Web.Administration
目前,网上关于Microsoft.Web.Administration的有效教程比较少,感觉入门难点主要是不知道自己需要的功能在什么位置,特写下此篇文章供大家参考.
1 Microsoft.Web.Administration.ServerManager sm = new Microsoft.Web.Administration.ServerManager(); 2 3 4 5 System.Console.WriteLine("应用程序池默认设置:"); 6 7 System.Console.WriteLine("/t常规:"); 8 9 System.Console.WriteLine("/t/t.NET Framework 版本:{0}", sm.ApplicationPoolDefaults.ManagedRuntimeVersion); 10 11 System.Console.WriteLine("/t/t队列长度:{0}", sm.ApplicationPoolDefaults.QueueLength); 12 13 System.Console.WriteLine("/t/t托管管道模式:{0}", sm.ApplicationPoolDefaults.ManagedPipelineMode.ToString()); 14 15 System.Console.WriteLine("/t/t自动启动:{0}", sm.ApplicationPoolDefaults.AutoStart); 16 17 18 19 System.Console.WriteLine("/tCPU:"); 20 21 System.Console.WriteLine("/t/t处理器关联掩码:{0}", sm.ApplicationPoolDefaults.Cpu.SmpProcessorAffinityMask); 22 23 System.Console.WriteLine("/t/t限制:{0}", sm.ApplicationPoolDefaults.Cpu.Limit); 24 25 System.Console.WriteLine("/t/t限制操作:{0}", sm.ApplicationPoolDefaults.Cpu.Action.ToString()); 26 27 System.Console.WriteLine("/t/t限制间隔(分钟):{0}", sm.ApplicationPoolDefaults.Cpu.ResetInterval.TotalMinutes); 28 29 System.Console.WriteLine("/t/t已启用处理器关联:{0}", sm.ApplicationPoolDefaults.Cpu.SmpAffinitized); 30 31 32 33 System.Console.WriteLine("/t回收:"); 34 35 System.Console.WriteLine("/t/t发生配置更改时禁止回收:{0}", sm.ApplicationPoolDefaults.Recycling.DisallowRotationOnConfigChange); 36 37 System.Console.WriteLine("/t/t固定时间间隔(分钟):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Time.TotalMinutes); 38 39 System.Console.WriteLine("/t/t禁用重叠回收:{0}", sm.ApplicationPoolDefaults.Recycling.DisallowOverlappingRotation); 40 41 System.Console.WriteLine("/t/t请求限制:{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Requests); 42 43 System.Console.WriteLine("/t/t虚拟内存限制(KB):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Memory); 44 45 System.Console.WriteLine("/t/t专用内存限制(KB):{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.PrivateMemory); 46 47 System.Console.WriteLine("/t/t特定时间:{0}", sm.ApplicationPoolDefaults.Recycling.PeriodicRestart.Schedule.ToString()); 48 49 System.Console.WriteLine("/t/t生成回收事件日志条目:{0}", sm.ApplicationPoolDefaults.Recycling.LogEventOnRecycle.ToString()); 50 51 52 53 System.Console.WriteLine("/t进程孤立:"); 54 55 System.Console.WriteLine("/t/t可执行文件:{0}", sm.ApplicationPoolDefaults.Failure.OrphanActionExe); 56 57 System.Console.WriteLine("/t/t可执行文件参数:{0}", sm.ApplicationPoolDefaults.Failure.OrphanActionParams); 58 59 System.Console.WriteLine("/t/t已启用:{0}", sm.ApplicationPoolDefaults.Failure.OrphanWorkerProcess); 60 61 62 63 System.Console.WriteLine("/t进程模型:"); 64 65 System.Console.WriteLine("/t/tPing 间隔(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.PingInterval.TotalSeconds); 66 67 System.Console.WriteLine("/t/tPing 最大响应时间(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.PingResponseTime.TotalSeconds); 68 69 System.Console.WriteLine("/t/t标识:{0}", sm.ApplicationPoolDefaults.ProcessModel.IdentityType); 70 71 System.Console.WriteLine("/t/t用户名:{0}", sm.ApplicationPoolDefaults.ProcessModel.UserName); 72 73 System.Console.WriteLine("/t/t密码:{0}", sm.ApplicationPoolDefaults.ProcessModel.Password); 74 75 System.Console.WriteLine("/t/t关闭时间限制(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.ShutdownTimeLimit.TotalSeconds); 76 77 System.Console.WriteLine("/t/t加载用户配置文件:{0}", sm.ApplicationPoolDefaults.ProcessModel.LoadUserProfile); 78 79 System.Console.WriteLine("/t/t启动时间限制(秒):{0}", sm.ApplicationPoolDefaults.ProcessModel.StartupTimeLimit.TotalSeconds); 80 81 System.Console.WriteLine("/t/t允许 Ping:{0}", sm.ApplicationPoolDefaults.ProcessModel.PingingEnabled); 82 83 System.Console.WriteLine("/t/t闲置超时(分钟):{0}", sm.ApplicationPoolDefaults.ProcessModel.IdleTimeout.TotalMinutes); 84 85 System.Console.WriteLine("/t/t最大工作进程数:{0}", sm.ApplicationPoolDefaults.ProcessModel.MaxProcesses); 86 87 88 89 System.Console.WriteLine("/t快速故障防护:"); 90 91 System.Console.WriteLine("/t/t“服务不可用”响应类型:{0}", sm.ApplicationPoolDefaults.Failure.LoadBalancerCapabilities.ToString()); 92 93 System.Console.WriteLine("/t/t故障间隔(分钟):{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtectionInterval.TotalMinutes); 94 95 System.Console.WriteLine("/t/t关闭可执行文件:{0}", sm.ApplicationPoolDefaults.Failure.AutoShutdownExe); 96 97 System.Console.WriteLine("/t/t关闭可执行文件参数:{0}", sm.ApplicationPoolDefaults.Failure.AutoShutdownParams); 98 99 System.Console.WriteLine("/t/t已启用:{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtection); 100 101 System.Console.WriteLine("/t/t最大故障数:{0}", sm.ApplicationPoolDefaults.Failure.RapidFailProtectionMaxCrashes); 102 103 System.Console.WriteLine("/t/t允许32位应用程序运行在64位 Windows 上:{0}", sm.ApplicationPoolDefaults.Enable32BitAppOnWin64); 104 105 106 107 System.Console.WriteLine(); 108 109 System.Console.WriteLine("网站默认设置:"); 110 111 System.Console.WriteLine("/t常规:"); 112 113 System.Console.WriteLine("/t/t物理路径凭据:UserName={0}, Password={1}", sm.VirtualDirectoryDefaults.UserName, sm.VirtualDirectoryDefaults.Password); 114 115 System.Console.WriteLine("/t/t物理路径凭据登录类型:{0}", sm.VirtualDirectoryDefaults.LogonMethod.ToString()); 116 117 System.Console.WriteLine("/t/t应用程序池:{0}", sm.ApplicationDefaults.ApplicationPoolName); 118 119 System.Console.WriteLine("/t/t自动启动:{0}", sm.SiteDefaults.ServerAutoStart); 120 121 System.Console.WriteLine("/t行为:"); 122 123 System.Console.WriteLine("/t/t连接限制:"); 124 125 System.Console.WriteLine("/t/t/t连接超时(秒):{0}", sm.SiteDefaults.Limits.ConnectionTimeout.TotalSeconds); 126 127 System.Console.WriteLine("/t/t/t最大并发连接数:{0}", sm.SiteDefaults.Limits.MaxConnections); 128 129 System.Console.WriteLine("/t/t/t最大带宽(字节/秒):{0}", sm.SiteDefaults.Limits.MaxBandwidth); 130 131 System.Console.WriteLine("/t/t失败请求跟踪:"); 132 133 System.Console.WriteLine("/t/t/t跟踪文件的最大数量:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.MaxLogFiles); 134 135 System.Console.WriteLine("/t/t/t目录:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.Directory); 136 137 System.Console.WriteLine("/t/t/t已启用:{0}", sm.SiteDefaults.TraceFailedRequestsLogging.Enabled); 138 139 System.Console.WriteLine("/t/t已启用的协议:{0}", sm.ApplicationDefaults.EnabledProtocols); 140 141 142 143 foreach (var s in sm.Sites)//遍历网站 144 145 { 146 147 System.Console.WriteLine(); 148 149 System.Console.WriteLine("模式名:{0}", s.Schema.Name); 150 151 System.Console.WriteLine("编号:{0}", s.Id); 152 153 System.Console.WriteLine("网站名称:{0}", s.Name); 154 155 System.Console.WriteLine("物理路径:{0}", s.Applications["/"].VirtualDirectories["/"].PhysicalPath); 156 157 System.Console.WriteLine("物理路径凭据:{0}", s.Methods.ToString()); 158 159 System.Console.WriteLine("应用程序池:{0}", s.Applications["/"].ApplicationPoolName); 160 161 System.Console.WriteLine("已启用的协议:{0}", s.Applications["/"].EnabledProtocols); 162 163 System.Console.WriteLine("自动启动:{0}", s.ServerAutoStart); 164 165 System.Console.WriteLine("运行状态:{0}", s.State.ToString()); 166 167 168 169 System.Console.WriteLine("网站绑定:"); 170 171 foreach (var tmp in s.Bindings) 172 173 { 174 175 System.Console.WriteLine("/t类型:{0}", tmp.Protocol); 176 177 System.Console.WriteLine("/tIP 地址:{0}", tmp.EndPoint.Address.ToString()); 178 179 System.Console.WriteLine("/t端口:{0}", tmp.EndPoint.Port.ToString()); 180 181 System.Console.WriteLine("/t主机名:{0}", tmp.Host); 182 183 //System.Console.WriteLine(tmp.BindingInformation); 184 185 //System.Console.WriteLine(tmp.CertificateStoreName); 186 187 //System.Console.WriteLine(tmp.IsIPPortHostBinding); 188 189 //System.Console.WriteLine(tmp.IsLocallyStored); 190 191 //System.Console.WriteLine(tmp.UseDsMapper); 192 193 } 194 195 196 197 System.Console.WriteLine("连接限制:"); 198 199 System.Console.WriteLine("/t连接超时(秒):{0}", s.Limits.ConnectionTimeout.TotalSeconds); 200 201 System.Console.WriteLine("/t最大并发连接数:{0}", s.Limits.MaxConnections); 202 203 System.Console.WriteLine("/t最大带宽(字节/秒):{0}", s.Limits.MaxBandwidth); 204 205 206 207 System.Console.WriteLine("失败请求跟踪:"); 208 209 System.Console.WriteLine("/t跟踪文件的最大数量:{0}", s.TraceFailedRequestsLogging.MaxLogFiles); 210 211 System.Console.WriteLine("/t目录:{0}", s.TraceFailedRequestsLogging.Directory); 212 213 System.Console.WriteLine("/t已启用:{0}", s.TraceFailedRequestsLogging.Enabled); 214 215 216 217 System.Console.WriteLine("日志:"); 218 219 //System.Console.WriteLine("/t启用日志服务:{0}", s.LogFile.Enabled); 220 221 System.Console.WriteLine("/t格式:{0}", s.LogFile.LogFormat.ToString()); 222 223 System.Console.WriteLine("/t目录:{0}", s.LogFile.Directory); 224 225 System.Console.WriteLine("/t文件包含字段:{0}", s.LogFile.LogExtFileFlags.ToString()); 226 227 System.Console.WriteLine("/t计划:{0}", s.LogFile.Period.ToString()); 228 229 System.Console.WriteLine("/t最大文件大小(字节):{0}", s.LogFile.TruncateSize); 230 231 System.Console.WriteLine("/t使用本地时间进行文件命名和滚动更新:{0}", s.LogFile.LocalTimeRollover); 232 233 234 235 System.Console.WriteLine("----应用程序的默认应用程序池:{0}", s.ApplicationDefaults.ApplicationPoolName); 236 237 System.Console.WriteLine("----应用程序的默认已启用的协议:{0}", s.ApplicationDefaults.EnabledProtocols); 238 239 //System.Console.WriteLine("----应用程序的默认物理路径凭据:{0}", s.ApplicationDefaults.Methods.ToString()); 240 241 //System.Console.WriteLine("----虚拟目录的默认物理路径凭据:{0}", s.VirtualDirectoryDefaults.Methods.ToString()); 242 243 System.Console.WriteLine("----虚拟目录的默认物理路径凭据登录类型:{0}", s.VirtualDirectoryDefaults.LogonMethod.ToString()); 244 245 System.Console.WriteLine("----虚拟目录的默认用户名:{0}", s.VirtualDirectoryDefaults.UserName); 246 247 System.Console.WriteLine("----虚拟目录的默认用户密码:{0}", s.VirtualDirectoryDefaults.Password); 248 249 System.Console.WriteLine("应用程序 列表:"); 250 251 foreach (var tmp in s.Applications) 252 253 { 254 255 if (tmp.Path != "/") 256 257 { 258 259 System.Console.WriteLine("/t模式名:{0}", tmp.Schema.Name); 260 261 System.Console.WriteLine("/t虚拟路径:{0}", tmp.Path); 262 263 System.Console.WriteLine("/t物理路径:{0}", tmp.VirtualDirectories["/"].PhysicalPath); 264 265 //System.Console.WriteLine("/t物理路径凭据:{0}", tmp.Methods.ToString()); 266 267 System.Console.WriteLine("/t应用程序池:{0}", tmp.ApplicationPoolName); 268 269 System.Console.WriteLine("/t已启用的协议:{0}", tmp.EnabledProtocols); 270 271 } 272 273 System.Console.WriteLine("/t虚拟目录 列表:"); 274 275 foreach (var tmp2 in tmp.VirtualDirectories) 276 277 { 278 279 if (tmp2.Path != "/") 280 281 { 282 283 System.Console.WriteLine("/t/t模式名:{0}", tmp2.Schema.Name); 284 285 System.Console.WriteLine("/t/t虚拟路径:{0}", tmp2.Path); 286 287 System.Console.WriteLine("/t/t物理路径:{0}", tmp2.PhysicalPath); 288 289 //System.Console.WriteLine("/t/t物理路径凭据:{0}", tmp2.Methods.ToString()); 290 291 System.Console.WriteLine("/t/t物理路径凭据登录类型:{0}", tmp2.LogonMethod.ToString()); 292 293 } 294 295 } 296 297 } 298 299 }
学习永无止境