您现在的位置: 365建站网 > 365学习 > PHP模块中使用appcmd.exe添加FastCGI映射的方法

PHP模块中使用appcmd.exe添加FastCGI映射的方法

文章来源:365jz.com     点击数:212    更新时间:2018-07-31 14:08   参与评论

配置示例

以下示例包含两个<add>定义处理程序映射的元素。第一个<add>元素为在IIS 7集成模式下运行的Web应用程序定义SampleHandler处理程序。如果将处理程序程序集添加到Web应用程序的app_code目录中,则不需要在type属性的值中包含程序集名称第二个<add>元素定义了使用FastCGI模块的PHP请求的映射。

<handlers>
   <add name="SampleHandler" verb="*" 
      path="SampleHandler.new" 
      type="SampleHandler, SampleHandlerAssembly" 
      resourceType="Unspecified" />
   <add name="PHP-FastCGI" verb="*" 
      path="*.php" 
      modules="FastCgiModule"
      scriptProcessor="c:\php\php-cgi.exe" 
      resourceType="Either" /></handlers>

示例代码

以下示例为PHP模块添加FastCGI映射,然后在Contoso Web站点上添加将处理PHP请求的处理程序。

Appcmd.exe的

appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='c:\php\php-cgi.exe']" /commit:apphostappcmd.exe set config "Contoso" -section:system.webServer/handlers /+"[name='PHP-FastCGI',path='*.php',verb='GET,HEAD,POST',modules='FastCgiModule',scriptProcessor='c:\php\php-cgi.exe',resourceType='Either']"

注意

第二个示例显示如何将特定URL的名为SampleHandler.new的新ASP.NET处理程序映射添加到Web应用程序。

appcmd.exe set config /section:system.webServer/handlers /+[name=SampleHandler',path='SampleHandler.new',verb='*',type='SampleHandler']

C#

using System;using System.Text;using Microsoft.Web.Administration;internal static class Sample{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration appHostConfig = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection fastCgiSection = appHostConfig.GetSection("system.webServer/fastCgi");
         ConfigurationElementCollection fastCgiCollection = fastCgiSection.GetCollection();
         ConfigurationElement applicationElement = fastCgiCollection.CreateElement("application");
         applicationElement["fullPath"] = @"c:\php\php-cgi.exe";
         fastCgiCollection.Add(applicationElement);
         Configuration webConfig = serverManager.GetWebConfiguration("Contoso");
         ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");
         ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
         ConfigurationElement addElement = handlersCollection.CreateElement("add");
         addElement["name"] = @"PHP-FastCGI";
         addElement["path"] = @"*.php";
         addElement["verb"] = @"GET,HEAD,POST";
         addElement["modules"] = @"FastCgiModule";
         addElement["scriptProcessor"] = @"c:\php\php-cgi.exe";
         addElement["resourceType"] = @"Either";
         handlersCollection.AddAt(0, addElement);
         serverManager.CommitChanges();
      }
   }}

VB.NET

Imports SystemImports System.TextImports Microsoft.Web.AdministrationModule Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim appHostConfig As Configuration = serverManager.GetApplicationHostConfiguration
      Dim fastCgiSection As ConfigurationSection = appHostConfig.GetSection("system.webServer/fastCgi")
      Dim fastCgiCollection As ConfigurationElementCollection = fastCgiSection.GetCollection
      Dim applicationElement As ConfigurationElement = fastCgiCollection.CreateElement("application")
      applicationElement("fullPath") = "c:\php\php-cgi.exe"
      fastCgiCollection.Add(applicationElement)
      Dim webConfig As Configuration = serverManager.GetWebConfiguration("Contoso")
      Dim handlersSection As ConfigurationSection = webConfig.GetSection("system.webServer/handlers")
      Dim handlersCollection As ConfigurationElementCollection = handlersSection.GetCollection
      Dim addElement As ConfigurationElement = handlersCollection.CreateElement("add")
      addElement("name") = "PHP-FastCGI"
      addElement("path") = "*.php"
      addElement("verb") = "GET,HEAD,POST"
      addElement("modules") = "FastCgiModule"
      addElement("scriptProcessor") = "c:\php\php-cgi.exe"
      addElement("resourceType") = "Either"
      handlersCollection.AddAt(0, addElement)
      serverManager.CommitChanges()
   End SubEnd Module

JavaScript的

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";var fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST");var fastCgiCollection = fastCgiSection.Collection;var applicationElement = fastCgiCollection.CreateNewElement("application");applicationElement.Properties.Item("fullPath").Value = "c:\\php\\php-cgi.exe";fastCgiCollection.AddElement(applicationElement);adminManager.CommitChanges();adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";var handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST/Contoso");var handlersCollection = handlersSection.Collection;var addElement = handlersCollection.CreateNewElement("add");addElement.Properties.Item("name").Value = "PHP-FastCGI";addElement.Properties.Item("path").Value = "*.php";addElement.Properties.Item("verb").Value = "GET,HEAD,POST";addElement.Properties.Item("modules").Value = "FastCgiModule";addElement.Properties.Item("scriptProcessor").Value = "c:\\php\\php-cgi.exe";addElement.Properties.Item("resourceType").Value = "Either";handlersCollection.AddElement(addElement, 0);adminManager.CommitChanges();

VBScript中

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"Set fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST")Set fastCgiCollection = fastCgiSection.CollectionSet applicationElement = fastCgiCollection.CreateNewElement("application")applicationElement.Properties.Item("fullPath").Value = "c:\php\php-cgi.exe"fastCgiCollection.AddElement applicationElementadminManager.CommitChanges()adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"Set handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST/Contoso")Set handlersCollection = handlersSection.CollectionSet addElement = handlersCollection.CreateNewElement("add")addElement.Properties.Item("name").Value = "PHP-FastCGI"addElement.Properties.Item("path").Value = "*.php"addElement.Properties.Item("verb").Value = "GET,HEAD,POST"addElement.Properties.Item("modules").Value = "FastCgiModule"addElement.Properties.Item("scriptProcessor").Value = "c:\php\php-cgi.exe"addElement.Properties.Item("resourceType").Value = "Either"handlersCollection.AddElement addElement, 0adminManager.CommitChanges()


如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛


发表评论 (212人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换图片
最新评论
------分隔线----------------------------