none
IIS 7/8 Microsoft.Web.Administration 设置aspSection.GetChildElement("limits") 属性无效 RRS feed

  • 问题

  •         /// <summary>
            /// 创建站点,并且设置新的应用程序池
            /// </summary>
            /// <param name="WebName">站点名称</param>
            /// <param name="Type">站点访问类型
            /// <para>http</para>
            /// <para>https</para>
            /// </param>
            /// <param name="IPInfo">IP 地址
            /// <para>格式:*:80: , *:端口:域名</para>
            /// </param>
            /// <param name="WebPath">网站所在物理路径</param>
            /// <param name="CLR">CLR版本</param>
            /// <param name="ErrorStr">错误信息</param>
            /// <returns></returns>
            //[ModuleServiceMethod(PassThrough = true)]
            public bool CreateSite(string WebName, string Type, string IPInfo, string WebPath, string CLR, Entity.IIS.system.webServer.asp ASP, out string ErrorStr)
            {
                try
                {
                    ServerManager iisManager = new ServerManager();
    
                    iisManager.Sites.Add(WebName, Type, IPInfo, WebPath);//创建网站
                    Site st = iisManager.Sites[WebName];//创建网站对象
    
                    //RequestCollection r = iisManager.WorkerProcesses.GetWorkerProcess(1).GetRequests(1);
    
                    //ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering");
                    //ConfigurationElementCollection filteringRulesCollection = requestFilteringSection.GetCollection("filteringRules");
    
                    //ConfigurationElement filteringRuleElement = filteringRulesCollection.CreateElement("filteringRule");
                    //filteringRuleElement["name"] = @"Block Image Leeching";
                    //filteringRuleElement["scanUrl"] = false;
                    //filteringRuleElement["scanQueryString"] = false;
                    //filteringRuleElement["scanAllRaw"] = false;
    
                    #region 应用程序池
                    if (!IsExistsApplicationPools(WebName))//不存在
                    {
                        iisManager.ApplicationPools.Add(WebName);  //创建应用程序池,设置与网站同名
                        //设置网站使用应用程序池
                        iisManager.Sites[WebName].Applications[0].ApplicationPoolName = WebName;
                        //创建应用程序池对象
                        ApplicationPool appPool = iisManager.ApplicationPools[WebName];
                        //设置应用程序池参数
                        appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//设置为集成模式;Integrated 集成;Classic 经典
                        appPool.ManagedRuntimeVersion = CLR;
                        appPool.AutoStart = true;//设置为自动启用
                        appPool.Failure.RapidFailProtection = true;//指示是否快速失败保护或关闭。
    
                        iisManager.CommitChanges();
                        //设置网站属性 ConfigurationElement
                        if (ASP != null)
                        {
                            Configuration config = iisManager.GetWebConfiguration(WebName);
                            ConfigurationSection aspSection = config.GetSection("system.webServer/asp", WebName);
    
    
                            //执行CMD %windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/limits
                            new Cmd().RunCmd(@"%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/limits");
                            //设置ASP->行为:服务设置***************************下面设置值无效?
                            ConfigurationElement limitsElement = aspSection.GetChildElement("limits");
                            //limitsElement.IsLocallyStored = true;
                            limitsElement["bufferingLimit"] = ASP.limits.bufferingLimit;
                            limitsElement["maxRequestEntityAllowed"] = ASP.limits.maxRequestEntityAllowed;
                            limitsElement["processorThreadMax"] = ASP.limits.processorThreadMax;
                            limitsElement["queueConnectionTestTime"] = ASP.limits.queueConnectionTestTime;
                            limitsElement["queueTimeout"] = ASP.limits.queueTimeout;
                            limitsElement["requestQueueMax"] = ASP.limits.requestQueueMax;
                            limitsElement["scriptTimeout"] = ASP.limits.scriptTimeout;
    
                        }
                        ErrorStr = "";
                    }
                    else
                    {
                        ErrorStr = WebName + " 应用程序池 已经存在!";
                    }
                    #endregion
                    return true;
                }
                catch (Exception ex)
                {
                    ErrorStr = ex.Message;
                    return false;
                }
            }
    

    例如:maxRequestEntityAllowed属性设置为200001,方法执行完后,查看IIS 确看到ASP中的,最大请求实体主体限制属性依然是200000

    下面是实体类代码:

        public class asp
        {
            /// <summary>
            /// 行为
            /// </summary>
            public limits limits=new limits();
        }
    
        public class limits
        {
            /// <summary>
            /// 脚本超时
            /// <para>指定ASP页在终止某个脚本并向Windows事件日志写入事件之前运行该脚本运行的默认时间长度。</para>
            /// </summary>
            public TimeSpan scriptTimeout = TimeSpan.Parse("00:01:30");
            /// <summary>
            /// 响应缓冲限制
            /// <para>设置ASP缓冲的最大大小。在启用响应缓冲功能时,此属性将控制ASP页可以写入响应缓冲的最大字节数,超过此数目后,将刷新缓冲。</para>
            /// </summary>
            public uint bufferingLimit = 4194304;
            /// <summary>
            /// 最大请求实体主体限制
            /// <para>指定ASP请求的实体主体中允许的最大字节数</para>
            /// </summary>
            public uint maxRequestEntityAllowed = 200000;
            /// <summary>
            /// 每个处理器的线程数限制
            /// <para>指定IIS可以为每个处理器创建最大工作线程数。</para>
            /// </summary>
            public uint processorThreadMax = 25;
            /// <summary>
            /// 客户端连接测试间隔
            /// <para>如果请求的排队时间超过此属性指定的时间,则ASP在执行请求之前将检查客户端是否仍处于连接状态。如果客户端已断开连接,则不会处理请求将其从队列中删除。</para>
            /// </summary>
            public TimeSpan queueConnectionTestTime = TimeSpan.Parse("00:00:03");
            /// <summary>
            /// 请求队列超时
            /// <para>指定允许ASP脚本请求在队列中排队等候的时间</para>
            /// </summary>
            public TimeSpan queueTimeout = TimeSpan.Parse("00:00:00");
            /// <summary>
            /// 队列长度
            /// <para>指定允许静茹队列的并发ASP请求的最大数量</para>
            /// </summary>
            public uint requestQueueMax = 3000;
        }
    }

    • 已移动 Caillen 2015年4月27日 6:47
    2015年4月26日 4:41

答案

  • 你好:

    请尝试一下修改属性之后再次调用Commit方法:

    http://www.iis.net/configreference/system.applicationhost/sites/site/application

    Note: You must be sure to set the commit   parameter to apphost when you use AppCmd.exe to configure these settings.   This commits the configuration settings to the appropriate location section   in the ApplicationHost.config file.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年4月27日 6:09

全部回复

  • - -!发现问题了,修改属性是有效,不过没有配置到applicationHost.config;反而是配置到web.config;怎么才能配置到applicationHost.config呢?
    2015年4月26日 14:13
  • 你好:

    请尝试一下修改属性之后再次调用Commit方法:

    http://www.iis.net/configreference/system.applicationhost/sites/site/application

    Note: You must be sure to set the commit   parameter to apphost when you use AppCmd.exe to configure these settings.   This commits the configuration settings to the appropriate location section   in the ApplicationHost.config file.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年4月27日 6:09