共用方式為


模組 < 模組>

概觀

元素 <modules> 會指定當使用者連線到網站或應用程式時,IIS 管理員中可用的功能。 元素 <modules> 會以下列方式與 元素搭配 <moduleProviders> 使用:

  • 元素 <moduleProviders> 會指定 IIS 管理員的模組提供者清單。
  • 元素 <modules> 會指定當使用者連線到網站或應用程式至 IIS 管理員時,會顯示為功能模組的清單。

您可以使用標籤來設定可供個別網站使用的 <location> 模組,以便自訂每個網站或應用程式,以符合您的需求。 例如,您可以設定網站的月臺層級管理,只允許一小部分的功能,並針對更廣泛的功能設定子應用程式。

注意

此模組集合專屬於 IIS 管理員,不應與< system.webServer modules 集合混淆,這會定義影響 HTTP 要求處理的模組 >

注意

元素中的 <modules> 設定只能在 Administration.config 檔案中設定。

相容性

版本 備註
IIS 10.0 <modules> IIS 10.0 中未修改專案。
IIS 8.5 <modules> 在 IIS 8.5 中修改專案。
IIS 8.0 在 IIS 8.0 中未修改專案 <modules>
IIS 7.5 <modules> 在 IIS 7.5 中修改專案。
IIS 7.0 專案 <modules> 是在 IIS 7.0 中引進的。
IIS 6.0 N/A

安裝程式

專案 <modules> 包含在 IIS 7 的預設安裝中。

作法

沒有使用者介面可以將模組新增至 <modules> IIS 7 的 元素。 For examples of how to add modules to the <modules> element programmatically, see the Code Samples section of this document.

組態

屬性

無。

子元素

屬性 描述
add 選擇性項目。 將模組新增至 IIS 管理員的模組集合。
clear 選擇性項目。 從父模組集合中移除模組的所有參考。
remove 選擇性項目。 從 IIS 管理員的模組集合中移除模組的參考。

組態範例

下列範例組態摘錄自Administration.config檔案會將名為 ContosoProvider 的受控模組提供者新增至集合結尾 <modules>

注意

此範例組態摘錄已縮短,方便閱讀。

<location path=".">
   <modules>
      <add name="Modules" />
      <add name="Handlers" />

      . . .
      . . .
      . . .

      <add name="ContosoProvider" />
   </modules>
</location>

下列範例組態摘錄自 Administration.config 檔案,藉由定義清除預設模組清單的唯 <location> 一元素,並定義每個位置分別啟用的特定模組,以指定預設網站和子應用程式的自訂 <modules> 元素。 當遠端系統管理連線到任一位置時,IIS 管理員只會顯示每個 <location> 元素中所列模組所代表的功能。

<location path="Default Web Site">
   <modules>
      <clear />
      <add name="DefaultDocument" />
      <add name="DirectoryBrowse" />
   </modules>
</location>

<location path="Default Web Site/ContosoApplication">
   <modules>
      <clear />
      <add name="DefaultDocument" />
      <add name="DirectoryBrowse" />
      <add name="Handlers" />
   </modules>
</location>

範例程式碼

下列程式碼範例會將名為 ContosoProvider 的受控模組提供者啟用至Administration.config檔案中的全域位置層級。

AppCmd.exe

注意

您無法使用 AppCmd.exe 來設定 <modules> 設定。

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.GetAdministrationConfiguration();
         ConfigurationSection modulesSection = config.GetSection("modules");

         ConfigurationElementCollection modulesCollection = modulesSection.GetCollection();
         ConfigurationElement addElement = modulesCollection.CreateElement("add");
         addElement["name"] = @"ContosoProvider";
         modulesCollection.Add(addElement);

         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.GetAdministrationConfiguration
      Dim modulesSection As ConfigurationSection = config.GetSection("modules")

      Dim modulesCollection As ConfigurationElementCollection = modulesSection.GetCollection
      Dim addElement As ConfigurationElement = modulesCollection.CreateElement("add")
      addElement("name") = "ContosoProvider"
      modulesCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager"); 
adminManager.CommitPath = "MACHINE/WEBROOT"; 
adminManager.SetMetadata("pathMapper", "AdministrationConfig");
var modulesSection = adminManager.GetAdminSection("modules", "MACHINE/WEBROOT"); 

var modulesCollection = modulesSection.Collection;
var addElement = modulesCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoProvider";
modulesCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"
Set modulesSection = adminManager.GetAdminSection("modules", "MACHINE/WEBROOT")

Set modulesCollection = modulesSection.Collection
Set addElement = modulesCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoProvider"
modulesCollection.AddElement(addElement)

adminManager.CommitChanges()