Compartilhar via


Regras de Autorização de Gerenciamento <authorizationRules>

Visão geral

O elemento <authorizationRules> do elemento <authorization> especifica quais usuários do Gerenciador do IIS e usuários do Windows estão autorizados a se conectar a um site ou aplicativo usando o Gerenciador do IIS quando o provedor de autorização padrão, ConfigurationAuthorizationProvider, estiver habilitado no IIS (Serviços de Informações da Internet) 7.

Observação

O ConfigurationAuthorizationProvider usa o arquivo Administration.config do IIS para armazenar as configurações de autorização do Gerenciador do IIS para o Gerenciador do IIS; no entanto, outros provedores de autorização podem usar locais de armazenamento alternativos.

Compatibilidade

Versão Observações
IIS 10.0 O elemento <authorizationRules> não foi modificado no IIS 10.0.
IIS 8.5 O elemento <authorizationRules> não foi modificado no IIS 8.5.
IIS 8.0 O elemento <authorizationRules> não foi modificado no IIS 8.0.
IIS 7.5 O elemento <authorizationRules> não foi modificado no IIS 7.5.
IIS 7.0 O elemento <authorizationRules> do elemento <authorization> foi introduzido no IIS 7.0.
IIS 6,0 N/D

Instalação

A instalação padrão do IIS 7 e posterior não inclui o serviço de função Serviço de Gerenciamento. Para instalar esse serviço de função, siga as etapas a seguir.

Windows Server 2012 R2 ou Windows Server 2012

  1. Na barra de tarefas, clique em Gerenciador do Servidor.
  2. No Gerenciador do Servidor, clique no menu Gerenciar e clique em Adicionar Funções e Recursos.
  3. No assistente Adicionar Funções e Recursos, clique em Avançar. Selecione o tipo de instalação e clique em Avançar. Selecione o servidor de destino e clique em Avançar.
  4. Na página Funções de Servidor, expanda Servidor Web (IIS), expanda Ferramentas de Gerenciamento e selecione Serviço de Gerenciamento. Clique em Avançar.
    Screenshot on the Server Roles page with the Management Service option being highlighted. .
  5. Na página Selecionar recursos, clique em Avançar.
  6. Na página Confirmar seleções de instalação, clique em Instalar.
  7. Na página Resultados , clique em Fechar.

Windows 8 ou Windows 8.1

  1. Na tela Iniciar, mova o ponteiro até o canto inferior esquerdo, clique com o botão direito do mouse no botão Iniciar e clique em Painel de Controle.
  2. Em Painel de Controle, clique em Programas e Recursos e clique em Ativar ou desativar Recursos do Windows.
  3. Expanda Serviços de Informações da Internet, expanda Ferramentas de Gerenciamento da Web e selecione Serviço de Gerenciamento do IIS.
    Screenshot of the Internet Information Services folder with the I I S Management Service folder being highlighted.
  4. Clique em OK.
  5. Clique em Fechar.

Windows Server 2008 R2 ou Windows Server 2008

  1. Na barra de tarefas, clique em Iniciar, vá para Ferramentas Administrativas e clique em Gerenciador do Servidor.
  2. No painel de hierarquia do Gerenciador do Servidor, expanda Funções e clique em Servidor Web (IIS).
  3. No painel Servidor Web (IIS), role até a seção Serviços de Função e clique em Adicionar Serviços de Função.
  4. Na página Selecionar Serviços de Função do Assistente para Adicionar Serviços de Função, selecione Serviço de Gerenciamento e clique em Avançar.
    Screenshot of the Add Role Services Wizard with the Management Service option being highlighted.
  5. Na página Confirmar Seleções de Instalação, clique em Instalar.
  6. Na página Resultados , clique em Fechar.

Windows Vista ou Windows 7

  1. Na barra de tarefas, clique em Iniciar e, depois, em Painel de Controle.
  2. Em Painel de Controle, clique em Programas e Recursos e clique em Ativar ou desativar Recursos do Windows.
  3. Expanda Serviços de Informação da Internet e selecione Ferramenta de Gerenciamento da Web.
  4. Selecione Serviço de gerenciamento do IIS e clique em OK.
    Screenshot of the Management Service screen with the Enable remote connections option being selected.

Instruções

Como autorizar um usuário do Gerenciador do IIS para um site ou aplicativo

  1. Abra o Gerenciador dos Serviços de Informações da Internet (IIS):

    • Caso você esteja usando o Windows Server 2012 ou o Windows Server 2012 R2:

      • Na barra de tarefas, clique em Gerenciador do Servidor, em Ferramentas e em Gerenciador dos Serviços de Informações da Internet (IIS).
    • Se você estiver usando o Windows 8 ou Windows 8.1:

      • Mantenha pressionada a tecla Windows, pressione a letra X e clique em Painel de Controle.
      • Clique em Ferramentas Administrativas e clique duas vezes em Gerenciador dos Serviços de Informações da Internet (IIS).
    • Caso você esteja usando o Windows Server 2008 ou o Windows Server 2008 R2:

      • Na barra de tarefas, clique em Iniciar, vá para Ferramentas Administrativas e clique em Gerenciador dos Serviços de Informações da Internet (IIS).
    • Se você estiver usando o Windows Vista ou Windows 7:

      • Na barra de tarefas, clique em Iniciar e, depois, em Painel de Controle.
      • Clique duas vezes em Ferramentas Administrativas e clique duas vezes em Gerenciador dos Serviços de Informações da Internet (IIS).
  2. No painel Conexões, acesse a conexão, o site, o aplicativo ou o diretório para o qual você deseja autorizar um usuário do Gerenciador do IIS.

  3. No painel Página Inicial, clique duas vezes em Permissões do Gerenciador do IIS.
    Screenshot of the I I S Manager Permissions shortcut in the Home pane.

  4. Na página Permissões do Gerenciador do IIS, clique em Permitir Usuário no painel Ações.
    Screenshot of the I I S Manager Permissions page.

  5. Na caixa de diálogo Permitir Usuário, escolha Gerenciador do IIS e clique em Selecionar...
    Screenshot of the Allow User dialog box with I I S Manager option being selected.

  6. Na caixa de diálogo Usuários, realce a conta de usuário que você deseja permitir e clique em OK.
    Screenshot of the Users dialog box with the user account being highlighted.

  7. Na caixa de diálogo Permitir Usuário, clique em OK.
    Screenshot of the Allow User dialog box with the selected user account populating the I I S Manager field.

Configuração

Atributos

Nenhum.

Elementos filho

Elemento Descrição
scope Elemento opcional.

Configura o caminho virtual do site ou aplicativo ao qual os usuários do Gerenciador do IIS e do Windows estão autorizados a se conectar usando o Gerenciador do IIS.

Exemplo de configuração

O exemplo de configuração a seguir mostra como autorizar um usuário do Gerenciador do IIS chamado Contoso, um grupo do Windows chamado Grupo de Teste e um usuário do Windows chamado Contoso2 a se conectar ao Site Padrão usando o Gerenciador do IIS.

<authorizationRules>
   <scope path="/Default Web Site">
      <add name="Contoso" />
      <add name="COMPUTER01\Test Group" isRole="true" />
      <add name="COMPUTER01\Contoso2" />
   </scope>
</authorizationRules>

Exemplo de código

Os exemplos de código a seguir verificam se um elemento <scope> já foi adicionado ao elemento <authorizationRules> para o Site Padrão, caso contrário, um elemento <scope> é adicionado ao elemento <authorizationRules>. Em seguida, um elemento <add> é adicionado ao elemento <scope> que autoriza uma conta de usuário chamada ContosoUser.

AppCmd.exe

Observação

Não é possível configurar as definições de <system.webServer/management/authorization> usando AppCmd.exe.

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