Share via


靜態內容 < staticContent>

概觀

元素 <staticContent> 會設定數個與在 Internet Information Services (IIS) 7 中處理靜態檔案要求相關的設定。

元素 <staticContent> 包含下列三個屬性,指定 IIS 7 是否應該將檔頁尾套用至靜態檔案:

  • enableDocFooter屬性會指定是否啟用檔頁尾。

  • defaultDocFooter 屬性包含下列其中一項:

    • 如果isDocFooterFileName屬性設定為false,IIS 7 將用於檔頁尾的文字字串
    • 檔案的完整路徑,如果 isDocFooterFileName 屬性設定為 true,IIS 7 將用於檔頁尾的文字。
  • 如上所述, isDocFooterFileName 屬性會指定 defaultDocFooter 屬性是否包含 IIS 7 將用於檔頁尾的文字字串,或是包含 IIS 7 將用於檔頁尾之文字的檔案完整路徑。

注意

根據預設, isDocFooterFileName 屬性會設定為 false 且全域鎖定。 若要使用檔頁尾的檔案,您必須在全域層級將 isDocFooterFileName 屬性設定為 true ,或解除鎖定屬性。 若要深入瞭解鎖定和解除鎖定屬性,請參閱 如何在 IIS 7.0 組態中使用鎖定 逐步解說。

相容性

版本 備註
IIS 10.0 <staticContent> IIS 10.0 中未修改專案。
IIS 8.5 <staticContent> 在 IIS 8.5 中修改專案。
IIS 8.0 在 IIS 8.0 中未修改專案 <staticContent>
IIS 7.5 <staticContent> 在 IIS 7.5 中修改專案。
IIS 7.0 專案 <staticContent> 是在 IIS 7.0 中引進的。
IIS 6.0 元素 <staticContent> 會取代下列 IIS 6.0 中繼基底屬性:
  • DefaultDocFooter
  • EnableDocFooter

安裝程式

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

作法

沒有用於設定 <staticContent> IIS 7 元素的使用者介面。 For examples of how to configure the <staticContent> element programmatically, see the Code Samples section of this document.

組態

屬性

屬性 描述
defaultDocFooter 選擇性字串屬性。

指定網站上每個網頁的預設頁尾文字,或包含預設頁尾文字的檔案路徑。 IIS 7 如何使用此屬性取決於 isDocFooterFileName 屬性的值。

注意: 只有在 enableDocFooter 屬性設定為 true時,才會傳送自訂頁尾。
enableDocFooter 選擇性的 Boolean 屬性。

指定預設 DocFooter 屬性所指示的文字是否會出現在網站上的每一個靜態頁面上。

預設值是 false
isDocFooterFileName 選擇性的 Boolean 屬性。

指定 defaultDocFooter 屬性中的字串是否包含檔案的路徑,其中包含網站上每個靜態網頁的預設頁尾文字。

預設值是 false

子元素

元素 描述
clientCache 選擇性項目。

指定快取傳送至用戶端之靜態內容的設定。
mimeMap 選擇性項目。

指定 MIME 對應副檔名的清單。

組態範例

下列組態範例會啟用靜態內容的檔頁尾,並將簡單的著作權聲明新增為頁尾文字。

<configuration>
   <system.webServer>
      <staticContent enableDocFooter="true"
         defaultDocFooter="The information in this web site is copyrighted." />
   </system.webServer>
</configuration>

範例程式碼

下列程式碼範例會啟用靜態內容的檔頁尾,並將簡單的著作權聲明新增為頁尾文字。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /enableDocFooter:"True"

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /defaultDocFooter:"The information in this web site is copyrighted."

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

         ConfigurationSection staticContentSection = config.GetSection("system.webServer/staticContent");
         staticContentSection["defaultDocFooter"] = @"The information in this web site is copyrighted.";
         staticContentSection["enableDocFooter"] = true;

         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.GetWebConfiguration("Default Web Site")

      Dim staticContentSection As ConfigurationSection = config.GetSection("system.webServer/staticContent")
      staticContentSection("defaultDocFooter") = "The information in this web site is copyrighted."
      staticContentSection("enableDocFooter") = True

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";

var staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site");
staticContentSection.Properties.Item("defaultDocFooter").Value = "The information in this web site is copyrighted.";
staticContentSection.Properties.Item("enableDocFooter").Value = true;

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"

Set staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site")
staticContentSection.Properties.Item("defaultDocFooter").Value = "The information in this web site is copyrighted."
staticContentSection.Properties.Item("enableDocFooter").Value = True

adminManager.CommitChanges()