管理授權規則範圍範圍 <>
概觀
元素 <scope>
的 <authorizationRules>
元素會指定在 Internet Information Services (IIS) 7 中啟用預設授權提供者 ConfigurationAuthorizationProvider時,遠端 IIS 管理員使用者和 Windows 使用者連線的月臺或應用程式虛擬路徑。
注意
ConfigurationAuthorizationProvider會使用 IIS Administration.config 檔案來儲存 IIS 管理員的 IIS 管理員授權設定;不過,其他授權提供者可能會使用替代儲存位置。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 在 <scope> IIS 10.0 中未修改專案。 |
IIS 8.5 | 未 <scope> 在 IIS 8.5 中修改專案。 |
IIS 8.0 | 在 IIS 8.0 中未修改專案 <scope> 。 |
IIS 7.5 | 未 <scope> 在 IIS 7.5 中修改專案。 |
IIS 7.0 | 元素 <scope> 的 <authorizationRules> 元素是在 IIS 7.0 中引進。 |
IIS 6.0 | N/A |
安裝程式
IIS 7 和更新版本的預設安裝不包含 管理服務角色服務 。 若要安裝此角色服務,請使用下列步驟。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在伺服器管理員中,按一下 [管理]功能表,然後按一下 [新增角色和功能]。
- 在 [ 新增角色和功能 精靈] 中,按 [下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,展開 [Web 服務器] ([IIS) ],展開 [ 管理工具],然後選取 [ 管理服務]。 按一下 [下一步] 。
.
- 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或Windows 8.1
- 在 [開始] 畫面上,將指標全部移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 展開 [Internet Information Services],展開 [Web 管理工具],然後選取 [ IIS 管理服務]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [Web 服務器 (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取 [管理服務],然後按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 展開 [Internet Information Services],然後展開 [Web 管理工具]。
- 選取 [IIS 管理服務],然後按一下 [ 確定]。
作法
如何授權網站或應用程式的 IIS 管理員使用者
(IIS) 管理員開啟 Internet Information Services:
如果您使用 Windows Server 2012 或 Windows Server 2012 R2:
- 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services] ([IIS) 管理員]。
如果您使用 Windows 8 或 Windows 8.1:
- 按住Windows鍵,按字母X,然後按一下[主控台]。
- 按一下 [ 系統管理工具],然後按兩下 [Internet Information Services] ([IIS) 管理員]。
如果您使用 Windows Server 2008 或 Windows Server 2008 R2:
- 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
如果您使用 Windows Vista 或 Windows 7:
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 按兩下 [ 系統管理工具],然後按兩下 [Internet Information Services] ([IIS) 管理員]。
在 [ 連線 ] 窗格中,移至您要授權 IIS 管理員使用者的連線、月臺、應用程式或目錄。
組態
屬性
屬性 | 描述 |
---|---|
path |
必要的字串屬性。 指定網站或應用程式的虛擬路徑。 然後,IIS 管理員使用者和 Windows 使用者可以新增至子< 新增 >集合,讓他們能夠使用 IIS 管理員連線到該網站或應用程式。 |
子元素
元素 | 描述 |
---|---|
add |
選擇性項目。 將 IIS 管理員使用者或 Windows 使用者或群組新增至已授權使用 IIS 管理員連線至網站或應用程式的使用者集合。 |
組態範例
下列設定範例示範如何授權名為 Contoso 的 IIS 管理員使用者、名為 Test Group 的 Windows 群組,以及名為 Contoso2 的 Windows 使用者,以使用 IIS 管理員連線到預設網站。
<authorizationRules>
<scope path="/Default Web Site">
<add name="Contoso" />
<add name="COMPUTER01\Test Group" isRole="true" />
<add name="COMPUTER01\Contoso2" />
</scope>
</authorizationRules>
範例程式碼
下列程式碼範例會檢查是否已 <scope>
將專案新增至 <authorizationRules>
預設網站的 元素;如果不是, <scope>
則會新增 <authorizationRules>
元素。 接下來,元素 <add>
會新增至 <scope>
授權名為 ContosoUser 之使用者帳戶的專案。
AppCmd.exe
注意
您無法使用 AppCmd.exe 來設定 <system.webServer/management/authorization>
設定。
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 authorizationSection = config.GetSection("system.webServer/management/authorization");
ConfigurationElementCollection authorizationRulesCollection = authorizationSection.GetCollection("authorizationRules");
ConfigurationElement scopeElement = FindElement(authorizationRulesCollection, "scope", "path", @"/Default Web Site");
if (scopeElement == null)
{
scopeElement = authorizationRulesCollection.CreateElement("scope");
scopeElement["path"] = @"/Default Web Site";
authorizationRulesCollection.Add(scopeElement);
}
ConfigurationElementCollection scopeCollection = scopeElement.GetCollection();
ConfigurationElement addElement = scopeCollection.CreateElement("add");
addElement["name"] = @"ContosoUser";
scopeCollection.Add(addElement);
serverManager.CommitChanges();
}
}
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
{
foreach (ConfigurationElement element in collection)
{
if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
{
bool matches = true;
for (int i = 0; i < keyValues.Length; i += 2)
{
object o = element.GetAttributeValue(keyValues[i]);
string value = null;
if (o != null)
{
value = o.ToString();
}
if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
{
matches = false;
break;
}
}
if (matches)
{
return element;
}
}
}
return null;
}
}
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 authorizationSection As ConfigurationSection = config.GetSection("system.webServer/management/authorization")
Dim authorizationRulesCollection As ConfigurationElementCollection = authorizationSection.GetCollection("authorizationRules")
Dim scopeElement As ConfigurationElement = FindElement(authorizationRulesCollection, "scope", "path", "/Default Web Site")
If (scopeElement Is Nothing) Then
scopeElement = authorizationRulesCollection.CreateElement("scope")
scopeElement("path") = "/Default Web Site"
authorizationRulesCollection.Add(scopeElement)
End If
Dim scopeCollection As ConfigurationElementCollection = scopeElement.GetCollection
Dim addElement As ConfigurationElement = scopeCollection.CreateElement("add")
addElement("name") = "ContosoUser"
scopeCollection.Add(addElement)
serverManager.CommitChanges()
End Sub
Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
For Each element As ConfigurationElement In collection
If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
Dim matches As Boolean = True
Dim i As Integer
For i = 0 To keyValues.Length - 1 Step 2
Dim o As Object = element.GetAttributeValue(keyValues(i))
Dim value As String = Nothing
If (Not (o) Is Nothing) Then
value = o.ToString
End If
If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
matches = False
Exit For
End If
Next
If matches Then
Return element
End If
End If
Next
Return Nothing
End Function
End Module
JavaScript
var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager");
adminManager.CommitPath = "MACHINE/WEBROOT";
adminManager.SetMetadata("pathMapper", "AdministrationConfig");
var authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT");
var authorizationRulesCollection = authorizationSection.ChildElements.Item("authorizationRules").Collection;
var scopeElementPos = FindElement(authorizationRulesCollection, "scope", ["path", "/Default Web Site"]);
if (scopeElementPos == -1)
{
var scopeElement = authorizationRulesCollection.CreateNewElement("scope");
scopeElement.Properties.Item("path").Value = "/Default Web Site";
authorizationRulesCollection.AddElement(scopeElement);
}
else
{
var scopeElement = authorizationRulesCollection.Item(scopeElementPos);
}
var scopeCollection = scopeElement.Collection;
var addElement = scopeCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoUser";
scopeCollection.AddElement(addElement);
adminManager.CommitChanges();
function FindElement(collection, elementTagName, valuesToMatch) {
for (var i = 0; i < collection.Count; i++) {
var element = collection.Item(i);
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
VBScript
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"
Set authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT")
Set authorizationRulesCollection = authorizationSection.ChildElements.Item("authorizationRules").Collection
scopeElementPos = FindElement(authorizationRulesCollection, "scope", Array("path", "/Default Web Site"))
If scopeElementPos = -1 Then
Set scopeElement = authorizationRulesCollection.CreateNewElement("scope")
scopeElement.Properties.Item("path").Value = "/Default Web Site"
authorizationRulesCollection.AddElement(scopeElement)
Else
Set scopeElement = authorizationRulesCollection.Item(scopeElementPos)
End If
Set scopeCollection = scopeElement.Collection
Set addElement = scopeCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoUser"
scopeCollection.AddElement(addElement)
adminManager.CommitChanges()
Function FindElement(collection, elementTagName, valuesToMatch)
For i = 0 To CInt(collection.Count) - 1
Set element = collection.Item(i)
If element.Name = elementTagName Then
matches = True
For iVal = 0 To UBound(valuesToMatch) Step 2
Set property = element.GetPropertyByName(valuesToMatch(iVal))
value = property.Value
If Not IsNull(value) Then
value = CStr(value)
End If
If Not value = CStr(valuesToMatch(iVal + 1)) Then
matches = False
Exit For
End If
Next
If matches Then
Exit For
End If
End If
Next
If matches Then
FindElement = i
Else
FindElement = -1
End If
End Function