Compartir a través de


Administración de reglas de autorización <authorizationRules>

Información general

El elemento <authorizationRules> del elemento <authorization> especifica qué usuarios del Administrador de IIS y usuarios de Windows están autorizados para conectarse a un sitio o a una aplicación mediante el Administrador de IIS cuando el proveedor de autorización predeterminado, ConfigurationAuthorizationProvider, está habilitado en Internet Information Services (IIS) 7.

Nota:

ConfigurationAuthorizationProvider usa el archivo Administration.config de IIS para almacenar la configuración de autorización del Administrador de IIS para el Administrador de IIS; sin embargo, otros proveedores de autorización pueden usar ubicaciones de almacenamiento alternativas.

Compatibilidad

Versión Notas
IIS 10.0 El elemento <authorizationRules> no se modificó en IIS 10.0.
IIS 8.5 El elemento <authorizationRules> no se modificó en IIS 8.5.
IIS 8.0 El elemento <authorizationRules> no se modificó en IIS 8.0.
IIS 7.5 El elemento <authorizationRules> no se modificó en IIS 7.5.
IIS 7.0 El elemento <authorizationRules> del elemento <authorization> se introdujo en IIS 7.0.
IIS 6,0 N/D

Configuración

La instalación predeterminada de IIS 7 y versiones posteriores no incluye el servicio de rol de Servicio de administración. Para instalar este servicio de rol, siga estos pasos.

Windows Server 2012 o Windows Server 2012 R2

  1. En la barra de tareas, haga clic en Administrador del servidor.
  2. En Administrador del servidor, haga clic en el menú Administrar y, después, haga clic en Agregar roles y características.
  3. En el asistente para Agregar roles y características, haga clic en Siguiente. Seleccione el tipo de instalación y haga clic en Siguiente. Seleccione el servidor de destino y haga clic en Siguiente.
  4. En la página Roles de servidor, expanda Servidor web (IIS), expanda Herramientas de administración y, a continuación, seleccione Servicio de administración. Haga clic en Next.
    Screenshot on the Server Roles page with the Management Service option being highlighted..
  5. En la página Seleccionar características, haz clic en Siguiente.
  6. En la página Confirmar selecciones de instalación, haga clic en Instalar.
  7. En la página Resultados , haga clic en Cerrar.

Windows 8 o Windows 8.1

  1. En la pantalla Inicio, mueva el puntero hasta la esquina inferior izquierda, haga clic con el botón derecho en el botón Inicio y, a continuación, haga clic en Panel de control.
  2. En Panel de control, haga clic en Programas y características y después en Activar o desactivar las características de Windows.
  3. Expanda Internet Information Services, expanda Herramientas de administración web y seleccione Servicio de administración de IIS.
    Screenshot of the Internet Information Services folder with the I I S Management Service folder being highlighted.
  4. Haga clic en OK.
  5. Haga clic en Cerrar.

Windows Server 2008 o Windows Server 2008 R2

  1. En la barra de tareas, haga clic en Inicio, seleccione Herramientas administrativas y, luego, haga clic en Administrador del servidor.
  2. En el panel de jerarquía del Administrador del servidor, expanda Roles y, luego, haga clic en Servidor web (IIS).
  3. En el panel Servidor web (IIS), desplácese hasta la sección Servicios de rol y, luego, haga clic en Agregar servicios de rol.
  4. En la página Seleccionar servicios de rol del Asistente para agregar servicios de rol, seleccione Servicio de administración y haga clic en Siguiente.
    Screenshot of the Add Role Services Wizard with the Management Service option being highlighted.
  5. En la página Confirmar selecciones de instalación, haz clic en Instalar.
  6. En la página Resultados , haga clic en Cerrar.

Windows Vista o Windows 7

  1. En la barra de tareas, haga clic en Inicio y, luego, haga clic en Panel de control.
  2. En Panel de control, haga clic en Programas y características y después en Activar o desactivar las características de Windows.
  3. Expanda Internet Information Servicesy, a continuación , Herramienta de administración web.
  4. Seleccione Servicio de administración de IIS y, a continuación, haga clic en Aceptar.
    Screenshot of the Management Service screen with the Enable remote connections option being selected.

Procedimientos

Cómo autorizar a un usuario del administrador de IIS para un sitio o aplicación

  1. Abra el Administrador de Internet Information Services (IIS):

    • Si usa Windows Server 2012 o Windows Server 2012 R2:

      • En la barra de tareas, haga clic en Administrador del servidor, en Herramientas y, a continuación, en Administrador de Internet Information Services (IIS).
    • Si usa Windows 8 o Windows 8.1:

      • Mantenga presionada la tecla Windows, presione la letra X y haga clic en Panel de control.
      • En Panel de control, haga clic en Herramientas administrativas y, a continuación, haga doble clic en Administrador de Internet Information Services (IIS).
    • Si usa Windows Server 2008 o Windows Server 2008 R2:

      • En la barra de tareas, haga clic en Inicio, seleccione Herramientas administrativas y, a continuación, haga clic en Administrador de Internet Information Services (IIS).
    • Si usa Windows Vista o Windows 7:

      • En la barra de tareas, haga clic en Inicio y, luego, haga clic en Panel de control.
      • Haga doble clic en Herramientas administrativas y, a continuación, haga doble clic en Administrador de Internet Information Services (IIS).
  2. En el panel Conexiones, vaya a la conexión, el sitio, la aplicación o el directorio para el que desea autorizar a un usuario del administrador de IIS.

  3. En el panel Inicio, haga doble clic en Permisos del administrador de IIS.
    Screenshot of the I I S Manager Permissions shortcut in the Home pane.

  4. En la página Permisos del administrador de IIS, haga clic en Permitir usuario... en el panel Acciones.
    Screenshot of the I I S Manager Permissions page.

  5. En el cuadro de diálogo Permitir usuario, elija Administrador de IIS y, a continuación, haga clic en Seleccionar...
    Screenshot of the Allow User dialog box with I I S Manager option being selected.

  6. En el cuadro de diálogo Usuarios, resalte la cuenta de usuario que desea permitir y, a continuación, haga clic en Aceptar.
    Screenshot of the Users dialog box with the user account being highlighted.

  7. En el cuadro de diálogo Permitir usuario, haga clic en Aceptar.
    Screenshot of the Allow User dialog box with the selected user account populating the I I S Manager field.

Configuración

Atributos

Ninguno.

Elementos secundarios

Elemento Descripción
scope Elemento opcional.

Configura la ruta de acceso virtual del sitio o la aplicación a la que los usuarios del Administrador de IIS y los usuarios de Windows están autorizados para conectarse mediante el Administrador de IIS.

Ejemplo de configuración

En el siguiente ejemplo de configuración se muestra cómo autorizar a un usuario del administrador de IIS denominado Contoso, un grupo de Windows denominado Grupo de pruebas y un usuario de Windows denominado Contoso2 para conectarse al sitio web predeterminado mediante el administrador de IIS.

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

Código de ejemplo

Los ejemplos de código siguientes comprueban si ya se ha agregado un <scope> elemento al elemento para el <authorizationRules> sitio web predeterminado; si no es así, se agrega un <scope> elemento al <authorizationRules> elemento. A continuación, se agrega un elemento <add> al elemento <scope> que autoriza una cuenta de usuario denominada ContosoUser.

AppCmd.exe

Nota:

No se pueden configurar las opciones de <system.webServer/management/authorization> mediante 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