En IIS7, ¿es posible tener variables de entorno personalizadas por sitio web?

En IIS7, ¿es posible tener variables de entorno personalizadas por sitio web?

Estoy configurando IIS7.5 para la intranet de una empresa. El servidor albergará un sitio de "prueba" y otro de "producción". La variable de entorno que quiero personalizar por sitio es 'PERL5LIB.

Quiero que este servidor web contenga un entorno Perl CGI (no FastCGI). (ActiveState Perl v5.16, usando PerlIs.dll y PerlEx30.dll). Quiero que este entorno Perl CGI tenga módulos de 'prueba' y de 'producción', de modo que los módulos de prueba se puedan cargar al acceder al sitio de 'prueba'. Del mismo modo, los módulos de producción se cargarán al acceder al sitio 'prod'. Configurar PERL5LIB por sitio es la clave.

Apache haría esto con una directiva SetEnv asociada con la URL del sitio.

Respuesta1

Seguro que es posible, utiliza dos grupos de aplicaciones diferentes, las ejecuta con diferentes cuentas de usuario y establece variables de entorno basadas en el usuario.

El siguiente script de PowerShell muestra cómo hacer esto. Estoy usando ASP.NET en las páginas pero deberías poder hacer lo mismo en Perl. También necesita habilitar las secuencias de comandos de IIS PowerShell para usar la secuencia de comandos.

 Import-Module WebAdministration

 Function Prepare([string]$name,[int]$port)
 {
     # create a new directory for the site
     md c:\inetpub\site$name

     # create a new application pool
     New-WebAppPool "pool$name"

     # create a new site using the folder and pool we just created
     New-WebSite -name "site$name" -port $port -physicalpath "c:\inetpub\site$name" -applicationpool "pool$name"

     # Make sure the pool runs as applicationpoolidentity and loads its user profile
     set-webconfigurationproperty -pspath 'machine/webroot/apphost'  -filter "system.applicationhost/applicationpools/add[@name='pool$name']/processmodel" -name "identitytype" -value "applicationpoolidentity"
     set-webconfigurationproperty -pspath 'machine/webroot/apphost'  -filter "system.applicationhost/applicationpools/add[@name='pool$name']/processmodel" -name "loaduserprofile" -value "true"

     # create two pages, one to show the environment variable, the other to set it.
     "<%@ page %><html># <% response.write(system.environment.getenvironmentvariable(`"myvar`")) %> #</html>" | out-file  "c:\inetpub\site$name\default.aspx"
     "<%@ page %><%  system.environment.setenvironmentvariable(`"myvar`", `"i am site $name`", system.environmentvariabletarget.user) %>" | out-file "c:\inetpub\site$name\setenv.aspx"

     # hit the home page, just to get it started
     (new-object net.webclient).DownloadString("http://localhost:$port")
     # set our environment variable
     (new-object net.webclient).DownloadString("http://localhost:$port/setenv.aspx")
     # recycle the pool
     Restart-WebAppPool -Name "Pool$name"
     # wait a little bit to restart
     Start-Sleep -Milliseconds 500
     # hit the home page again to show our variable
     (new-object net.webclient).DownloadString("http://localhost:$port")
 }

 # call the function for two sites
 Prepare A 81
 Prepare B 82   

Solo probé esto en 2012 R2, pero debería funcionar bien en 2008 R2, no es necesario usar el script, puedes seguir los mismos pasos en la GUI.

información relacionada