IIS6 List the version of .net an application pool is running

痞子三分冷 提交于 2019-12-08 00:47:55

问题


I want to enumerate the application pools running on a server. In IIS7 i am able to pull up the .net version via WMI WIn32_Process but it is not there in IIS6. How can I get the version of .net that a worker process/application pool is running in?

For instance:

DefaultAppPool v2.0.50727

In IIS6 .Net is set in the Virtual Directories under the ASP.NET tab and the Application Pool is setup under the Virtual Directory tab. FYI: I'm running Windows 2003 SP2 IIS6.


回答1:


The problem with IIS6 Application Pools is that unlike IIS7 they have no knowledge of what version of the .NET Framework is being loaded into them.

IIS6 websites determine which .NET Framework runtime is loaded into a pool by the version of ASP.NET that is pointed to by a site or sub application's script maps. A worker process will just blindly load the requisite ISAPI DLL that is mapped to an extension (or whatever is defined in the wildcard mapping).

This old method is often the cause of much grief where two different sites allocated to the same pool may be configured to run different versions of ASP.NET and you get the infamous:

...and the following event is logged to the Windows Application Log:

Event Type: Error
Event Source:   ASP.NET 2.0.50727.0
Event Category: None
Event ID:   1062
Date:       12/01/2011
Time:       12:31:43
User:       N/A
Computer:   KK-DEBUG
Description:
It is not possible to run two different versions of ASP.NET in the same 
IIS process. Please use the IIS Administration Tool to reconfigure your
server to run the application in a separate process.

The only way to determine what .NET version an application pool is configured to run is to walk every site that is assigned that pool and check the raw scriptmaps.

The only problem with this is where (for example), for whatever reason, you have a misconfigured site (or sub application) that is no longer in use that is setup to use a different version of ASP.NET, e.g.:

Site                         .NET Version   Application Pool 
============================================================
WebSite1                     ASP.NET 4.0    AppPool1
WebSite2 (no longer used)    ASP.NET 2.0    AppPool1

In this case you have to decide which site takes precedence to determine the framework version.

This PowerShell script might help you ascertain what ASP.NET version is being used in each pool:

# Walk sites
$allsites = ([adsi]"IIS://Localhost/W3SVC").children | where { $_.SchemaClassName -eq "IIsWebServer" }
$pools = @()

foreach($site in $allsites)
{
  $path = "IIS://Localhost/W3SVC/" + $site.Name + "/root"
  $siteRoot = [adsi]$path
  $sitePool = $siteRoot.AppPoolId

  $aspx = $siteRoot.ScriptMaps | where { $_.StartsWith(".aspx") }

  if( $aspx.Contains("v1.1")) {
    $runtime = "1.1"
  } elseif ($aspx.Contains("v2.0")) {
    $runtime = "2.0"
  } elseif( $aspx.Contains("v4.0")) {
    $runtime = "4.0"
  } else {
    $runtime = "Unknown"
  }

  $v =  @{AppPool = $siteRoot.AppPoolId; RunTime = $runtime; SiteId = $site.Name}
  $pools += $v
}

$pools | Sort-Object { $_.AppPool } | % { Write-Host $_.AppPool $_.SiteId $_.RunTime }

It only walks the sites at the root level and doesn't recursively walk into each one to identify sub applications.




回答2:


I think you can execute the following statements:

$computer = "LocalHost" 
$namespace = "root\MicrosoftIISv2" 
Get-WmiObject -class IIsApplicationPoolSetting -computername $computer -namespace $namespace

and use the ManagedRuntimeVersion property in the returned object.

Edit: As Andy said in comment below, this doesn't work. However, if you are on WS2003 you might try this and parse the result returned:

C:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -lk

Knowing on what OS you are running would be nice.



来源:https://stackoverflow.com/questions/11149724/iis6-list-the-version-of-net-an-application-pool-is-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!