Tenemos algunas aplicaciones que necesitan hacer esto exactamente. A menudo, nuestras aplicaciones están bloqueados en el web.config:
<authentication mode="Windows"/>
<authorization>
<allow roles="DOMAIN\GroupNameHere"/>
<deny users="?"/>
</authorization>
<location path="ApiControllerName">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Sin embargo, todavía se tiene que apagar la autenticación de Windows para que el controlador de API. Usted puede hacer esto mediante la edición del archivo applicationHost.config
en el servidor IIS y añadiendo:
<location path="Default Web Site/ApplicationName/ApiControllerName">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
<windowsAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
Este script PowerShell lo hará por usted:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$applicationLocationPath = "Default Web Site/ApplicationName/ApiControllerName"
$oIIS = new-object Microsoft.Web.Administration.ServerManager
$oGlobalConfig = $oIIS.GetApplicationHostConfiguration()
$oSection = $oGlobalConfig.GetSection("system.webServer/security/authentication/anonymousAuthentication", $applicationLocationPath)
$oSection.SetAttributeValue("enabled", "True")
$oSection = $oGlobalConfig.GetSection("system.webServer/security/authentication/windowsAuthentication", $applicationLocationPath)
$oSection.SetAttributeValue("enabled", "False")
$oIIS.CommitChanges()
"sólo ha sido capaz de hacer uno o el otro", ¿cómo exactamente hiciste entonces? – bzlm
¿Cómo se ha habilitado exactamente la autenticación de Windows? – gideon
La configuración de IIS tiene habilitada la Autenticación de Windows y también permite Anónimo. Web.config tiene . Agregué el atributo [Autorizar] al controlador que necesitaba proteger y lo dejé fuera del controlador que quería exponer. –
Shawn