How to check whether ASP.NET 4.0 registered on IIS 7.5

zbynour picture zbynour · Mar 28, 2012 · Viewed 43k times · Source

Is there any reliable way how to check whether ASP.NET 4.0 registered on IIS 7.5 programmatically? I need to test it in the installer as prerequisite, before ASP.NET application installation start.

If ASP.NET 4.0 not registered on the IIS, later during the installation just installed application cannot be run and returns 500 internal server error (and it is too late to solve the problem). Instead, I want to show some warning (and hint how to solve the issue) before any installation steps started. But no reliable solution found yet.

AFAIK, registry entries reading sometimes may not work correctly. So now, I run aspnet_regiis.exe -lv to list versions (as suggested here) and parse the output. But even if .NET not registered correctly my test (falsely) succeeds, because the output is (contains version 4.0):

2.0.50727.0     C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll
4.0.30319.0     C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

(Win7 32bit)

Running aspnet_regiis.exe -ir can repair it in this case.

It's similar issue as this question, but I need test it programmatically.

Do you have any ideas or experiences?

Answer

Czenda picture Czenda · Dec 4, 2012

Using your own answer as a basis, this can also be done using the command line (with elevation):

%WINDIR%\System32\inetsrv\appcmd.exe list apppool /managedRuntimeVersion:v4.0

If anything is returned, ASP.NET 4.0 is registered. The issue with this approach is that it seems to be possible to create 4.0 application pools manually even if the filter is not installed, and then this method would not work.


EDIT: I have ended up running these three checks:

  1. aspnet_regiis.exe -lv (should return a line containing "c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll")
  2. appcmd.exe list apppool /managedRuntimeVersion:v4.0 (should return a line containing "MgdVersion:v4.0")
  3. appcmd.exe list config -section:system.webServer/isapiFilters (should return a line containing "c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll")

Note that I only care about 32bit versions.

If all three checks pass, it can be concluded that ASP.NET 4.0 is registered. Still not 100% false positive-proof though.