当前位置:   article > 正文

c# iis_c# iis

c# iis

引用:using Microsoft.Web.Administration;
对C:\Windows\System32\inetsrv\Config\redirection.config设置everyone访问权限,否则会出现权限不足无法访问配置文件的错误

网上找的代码:

            using (ServerManager sm = new ServerManager())
            {

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

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

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

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

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

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

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

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

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

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

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

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

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


            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/252420
推荐阅读
相关标签
  

闽ICP备14008679号