鎖住 Office SharePoint Server 網站
您可以透過啟用 Microsoft Office SharePoint Server 2007 網站的鎖定模式,限制匿名使用者的權限。如需 Office SharePoint Server 2007 中鎖定模式的詳細資訊,請參閱<規劃外部匿名存取環境的安全性 (Office SharePoint Server)>中的<使用鎖定模式>一節。
不過,即使啟用鎖定模式,匿名使用者仍然可以存取某些 Office SharePoint Server 應用程式 URL,例如,_layouts 目錄中的頁面和 _vti_bin 目錄中所公開的 Web 服務。本主題說明如何修改 Web.config 檔案以限制對這些額外資源的存取。
注意
若要提升 Office SharePoint Server 網站的安全性,您應該啟用鎖定模式並修改 Web.config 檔案,如本主題所述。
使用 Web.config 檔案允許和拒絕存取
您可以將 location 元素新增至 Web.config 檔案,以允許和拒絕對 Web 資源的存取。例如,您可以新增 location 元素以拒絕對 _layouts 目錄的匿名使用者存取,然後新增第二個 location 元素,以明確地允許對 _layouts/login.aspx 頁面的匿名使用者存取。第二個 location 元素會覆寫第一個 location 元素,並為登入頁面建立拒絕存取的例外狀況。
如需 location 元素的詳細資訊,請參閱<規劃外部匿名存取環境的安全性 (Office SharePoint Server)>中的<使用鎖定模式>一節。
注意
不建議直接編輯 Web.config 檔案。如果您直接修改 Web.config 檔案,當您升級 Office SharePoint Server 安裝時,有可能會覆寫該修改,或是可能無法將修改的 Web.config 檔案複製到伺服器陣列中的所有前端網頁伺服器。您應該建立特殊的 XML 檔案,將它儲存在 \Config 目錄中。在升級期間,Windows SharePoint Services 3.0 和 Office SharePoint Server 2007 都會尋找此目錄中的檔案,並將檔案中指定的變更套用至 Web.config 檔案,這樣就可以保存您所做的任何變更。如需在 Windows SharePoint Services 3.0 和 Office SharePoint Server 2007 中的 Web.config 檔案中保存自訂的詳細資訊,請參閱如何:新增自訂組態設定以擴充 Web 應用程式 (英文) (https://go.microsoft.com/fwlink/?linkid=157096&clcid=0x404)。
匿名使用者應具有哪些頁面的存取權?
若要允許匿名使用者通過伺服器的驗證,您應該確保他們具有下列頁面的存取權:
_layouts/login.aspx
_layouts/accessdenied.aspx
_layouts/error.aspx
如果您拒絕任何這些頁面的匿名使用者存取,Office SharePoint Server 將無法正常運作。
如果您已部署的自訂方案需要匿名使用者存取 _layouts 目錄中的其他頁面或 _vti_bin 目錄中的其他服務,請同時明確地允許這些資源的匿名存取。
範例
在本節中的前兩個範例說明限制匿名存取的可能策略,為了便於閱讀,兩個範例都提供 Web.config 檔案中顯示的 XML。第三個範例說明在 Windows SharePoint Services 和 Office SharePoint Server中將 XML 元素新增至 Web.config 檔案的正確方式。
重要
請勿將前兩個範例之一的 XML 陳述式直接新增至 Web.config 檔案。請建立一個類似第三個範例的檔案,將它儲存在 \Config 目錄中,如如何:新增自訂組態設定以擴充 Web 應用程式 (英文) (https://go.microsoft.com/fwlink/?linkid=157096&clcid=0x404) 中所說明。
範例 1:拒絕存取所有項目,選擇性地允許存取特定資源
下列 XML 片段先拒絕匿名使用者存取 _layouts 和 _vti_bin 目錄中所有頁面,然後允許匿名使用者存取 _layouts 目錄中四個特定頁面。問號 (?
) 代表匿名使用者。這些限制不適用於經過驗證的使用者。
<configuration>
<location path="_layouts">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="_vti_bin">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/login.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/error.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/accessdenied.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
</configuration>
範例 2:拒絕存取特定資源
下列 XML 片段拒絕匿名使用者存取 _layouts/error.aspx 和 _layouts/SearchResults.aspx。對 _layouts 目錄中其他頁面的存取則會受到網站鎖定模式狀態的控制。問號 (?
) 代表匿名使用者。這些限制不適用於經過驗證的使用者。
<configuration>
<location path="_layouts/error.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/SearchResults.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<configuration>
範例 3:實作範例 1 的建議方式
下列 XML 陳述式說明如何將範例 1 的 XML 陳述式新增至 Web.config 檔案,透過這種方式,當更新 Windows SharePoint Services 或 Office SharePoint Server 時,就能保存這些新增內容,如 如何:新增自訂組態設定以擴充 Web 應用程式 (英文) (https://go.microsoft.com/fwlink/?linkid=157096&clcid=0x404) 中所述。
<?xml version="1.0" encoding="utf-8" ?>
<actions>
<add path="configuration">
<location path="_layouts">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="_vti_bin">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/login.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/error.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="_layouts/accessdenied.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
</add>
</actions>
在建立了包含類似範例 3 之 XML 陳述式的檔案後,請以 webconfig. <名稱>.xml 格式命名此檔案,將檔案儲存在 \Config 目錄中。若要將這些變更套用至伺服器陣列,請在每部前端網頁伺服器上執行 Stsadm copyappobincontent 作業。如需詳細資訊,請參閱<Copyappbincontent:Stsadm 作業 (Office SharePoint Server)>。