none
IIS 7/8 Microsoft.Web.Administration.Request 怎么使用? 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>
            public bool CreateSite(string WebName, string Type, string IPInfo, string WebPath,string CLR, out string ErrorStr)
            {
                try
                {
                    ServerManager iisManager = new ServerManager();
                    
                    iisManager.Sites.Add(WebName, Type, IPInfo, WebPath);//创建网站
                    Site st = iisManager.Sites[WebName];//创建网站对象
                    //设置网站属性 ConfigurationElement
    
                    //Request rp = iisManager.GetRedirectionConfiguration();
    
    
                    #region 应用程序池
                    
                    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;//指示是否快速失败保护或关闭。
    
                    #endregion
                    iisManager.CommitChanges();
                    ErrorStr = "";
                    return true;
                }
                catch (Exception ex)
                {
                    ErrorStr = ex.Message;
                    return false;
                } 
            }

    Microsoft.Web.Administration.Request  具体要怎么操作使用?

    我需要配置:

    请求筛选->编辑功能设置

    IIS->ASP 中的参数设置

    又要怎么做呢?

    2015年4月7日 8:29

答案

  • 你好,

    想用Request 类,我们可以用 ServerManager.WorkerProcesses.GetWorkerProcess().GetRequests() 方法来获得RequestCollection 集合,然后得到request 对象。

    另外请求筛选配置:

    Configuration config = serverManager.GetWebConfiguration("Default Web Site");
             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;
    

    ASP setting:

    ConfigurationSection aspSection = config.GetSection("system.webServer/asp", "Default Web Site");
    
             ConfigurationElement sessionElement = aspSection.GetChildElement("session");
             sessionElement["allowSessionState"] = true;
             sessionElement["max"] = 1000;
             sessionElement["timeout"] = TimeSpan.Parse("00:10:00");
    


    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月8日 3:13

全部回复

  • 你好,

    想用Request 类,我们可以用 ServerManager.WorkerProcesses.GetWorkerProcess().GetRequests() 方法来获得RequestCollection 集合,然后得到request 对象。

    另外请求筛选配置:

    Configuration config = serverManager.GetWebConfiguration("Default Web Site");
             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;
    

    ASP setting:

    ConfigurationSection aspSection = config.GetSection("system.webServer/asp", "Default Web Site");
    
             ConfigurationElement sessionElement = aspSection.GetChildElement("session");
             sessionElement["allowSessionState"] = true;
             sessionElement["max"] = 1000;
             sessionElement["timeout"] = TimeSpan.Parse("00:10:00");
    


    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月8日 3:13
  • 我使用时,出现了这个错误:

    limitsElement.IsLocallyStored;//是否该属性影响呢?如果是那么怎么解决呢?

    不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的(overrideModeDefault="Deny"),或者是通过包含 overrideMode="Deny" 或旧有的 allowOverride="false" 的位置标记明确设置的。
    以上的问题解决了,问题是:

    //执行CMD %windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/limits

    不过我又遇到另外一个问题,修改了属性参数无效;

    例如:sessionElement["max"] = 100;运行后打开IIS查看确还是1000;

    2015年4月26日 3:38