应用程序依赖项 <applicationDependencies>

概述

<security> 元素的 <applicationDependencies> 元素与 <isapiCgiRestriction> 元素协同工作,以定义哪些应用程序依赖于一个或多个 CGI 或 ISAPI 扩展限制。 如果应用程序包含在此元素中,则应用程序依赖于 <isapiCgiRestriction> 元素中的一个或多个项。

兼容性

版本 说明
IIS 10.0 <applicationDependencies> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <applicationDependencies> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <applicationDependencies> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <applicationDependencies> 元素在 IIS 7.5 中未进行修改。
IIS 7.0 IIS 7.0 中引入了 <security> 元素的 <applicationDependencies> 元素。
IIS 6.0 <applicationDependencies> 元素取代了 IIS 6.0 中 IIsWebService 元数据库对象的 ApplicationDependencies 属性。

安装

<applicationDependencies> 元素包含在 IIS 7 的默认安装中。

操作方式

IIS 7 中没有用于配置 <applicationDependencies> 元素的用户界面。 若要通过示例来了解如何以编程方式配置 <applicationDependencies> 元素,请参阅本文档的代码示例部分。

配置

特性

无。

子元素

元素 说明
application 可选元素。

指定一个对于一个或多个 CGI 或 ISAPI 扩展限制具有依赖性的应用程序。
clear 可选元素。

applicationDependencies 集合中移除对应用程序的所有引用。

配置示例

以下配置示例说明了在 IIS 7 上安装 Active Server Pages (ASP) 和自定义应用程序后,默认网站的 <applicationDependencies> 元素中的应用程序依赖项以及 <isapiCgiRestriction> 中的相关条目:

  • Active Server Pages 应用程序依赖于“ASP”ISAPI/CGI 限制组。
  • 自定义应用程序依赖于“MyCustomGroup”ISAPI/CGI 限制组,并且还依赖于 ASP ISAPI/CGI 限制组。
<system.webServer>
   <security>
      <isapiCgiRestriction notListedIsapisAllowed="false" notListedCgisAllowed="false">
         <clear />
         <add allowed="true" groupId="ASP"
            path="C:\Windows\system32\inetsrv\asp.dll" 
            description="Active Server Pages" />
         <add allowed="true" groupId="MyCustomGroup"
            path="C:\Windows\system32\inetsrv\mycustom.dll"
            description="My Custom Application" />
      </isapiCgiRestriction>
   </security>
</system.webServer>

<location path="Default Web Site">
   <system.webServer>
      <security>
         <applicationDependencies>
            <application name="My Custom Application" groupId="MyCustomGroup">
               <add groupId="ASP" />
            </application>
         </applicationDependencies>
      </security>
   </system.webServer>
</location>

代码示例

以下配置示例演示默认网站元素中的 <applicationDependencies> 应用程序依赖项。 自定义应用程序依赖于“MyCustomGroup”ISAPI/CGI 限制组,并且还依赖于 ASP ISAPI/CGI 限制组。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/security/applicationDependencies /+"[name='My Custom Application',groupId='MyCustomGroup']" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/security/applicationDependencies /+"[name='My Custom Application',groupId='MyCustomGroup'].[groupId='ASP']" /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection applicationDependenciesSection = config.GetSection("system.webServer/security/applicationDependencies", "Default Web Site");

         ConfigurationElementCollection applicationDependenciesCollection = applicationDependenciesSection.GetCollection();
         ConfigurationElement applicationElement = applicationDependenciesCollection.CreateElement("application");
         applicationElement["name"] = @"My Custom Application";
         applicationElement["groupId"] = @"MyCustomGroup";

         ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
         ConfigurationElement addElement = applicationCollection.CreateElement("add");
         addElement["groupId"] = @"ASP";
         applicationCollection.Add(addElement);
         applicationDependenciesCollection.Add(applicationElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim applicationDependenciesSection As ConfigurationSection = config.GetSection("system.webServer/security/applicationDependencies", "Default Web Site")

      Dim applicationDependenciesCollection As ConfigurationElementCollection = applicationDependenciesSection.GetCollection
      Dim applicationElement As ConfigurationElement = applicationDependenciesCollection.CreateElement("application")
      applicationElement("name") = "My Custom Application"
      applicationElement("groupId") = "MyCustomGroup"

      Dim applicationCollection As ConfigurationElementCollection = applicationElement.GetCollection
      Dim addElement As ConfigurationElement = applicationCollection.CreateElement("add")
      addElement("groupId") = "ASP"
      applicationCollection.Add(addElement)
      applicationDependenciesCollection.Add(applicationElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var applicationDependenciesSection = adminManager.GetAdminSection("system.webServer/security/applicationDependencies", "MACHINE/WEBROOT/APPHOST/Default Web Site");

var applicationDependenciesCollection = applicationDependenciesSection.Collection;
var applicationElement = applicationDependenciesCollection.CreateNewElement("application");
applicationElement.Properties.Item("name").Value = "My Custom Application";
applicationElement.Properties.Item("groupId").Value = "MyCustomGroup";

var applicationCollection = applicationElement.Collection;
var addElement = applicationCollection.CreateNewElement("add");
addElement.Properties.Item("groupId").Value = "ASP";
applicationCollection.AddElement(addElement);
applicationDependenciesCollection.AddElement(applicationElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set applicationDependenciesSection = adminManager.GetAdminSection("system.webServer/security/applicationDependencies", "MACHINE/WEBROOT/APPHOST/Default Web Site")

Set applicationDependenciesCollection = applicationDependenciesSection.Collection
Set applicationElement = applicationDependenciesCollection.CreateNewElement("application")
applicationElement.Properties.Item("name").Value = "My Custom Application"
applicationElement.Properties.Item("groupId").Value = "MyCustomGroup"

Set applicationCollection = applicationElement.Collection
Set addElement = applicationCollection.CreateNewElement("add")
addElement.Properties.Item("groupId").Value = "ASP"
applicationCollection.AddElement(addElement)
applicationDependenciesCollection.AddElement(applicationElement)

adminManager.CommitChanges()