20

The challenge is to determine whether ASP.NET is enabled within IIS7 in a reliable and correct way.

Enabling/Disabling is done in this case by going into:

Server Manager -> 
    Roles -> 
        Web Server (IIS) -> 
            Remove Role Services -> 
                Remove ASP.NET

The natural place to determine this should be within the applicationHost.config file. However, with ASP.NET enabled or disabled, we still have the "ManagedEngine" module available, and we still have the isapi filter record in the tag.

The best I can find at the moment is to check if the <isapiCgiRestriction> tag includes the aspnet_isapi.dll, or that the ASPNET trace provider is available.

However these aren't detecting the presence of the ASP.NET config directly, just a side effect that could conceivably be reconfigured by the user.

I'd rather do this by examining the IIS configuration/setup rather than the OS itself, if possible, although enumerating the Roles & Services on the server might be acceptable if we can guarantee that this technique will always work whenever IIS7 is used.

Update

Thanks for the responses. Clarifying exactly what I want to do, I'm pulling settings from a variety of places in the server's configuration into a single (readonly) view to show what the user needs to have configured to allow the software to work.

One of the settings I need to bring in is this one: IIS Config showing ASP.NET not installed

The one highlighted in red.

I don't need to manipulate the setting, just reproduce it. I want to see whether the user checked the ASP.NET box when they added the IIS role to the server, as in this example they clearly didn't.

I'd like to do this by looking at something reliable in IIS rather than enumerating the role services because I don't want to add any platform specific dependencies on the check that I don't need. I don't know if it will ever be possible to install IIS7 on a server that doesn't have the Roles/Services infrastructure, but in preference, I'd rather not worry about it. I also have a load of libraries for scrubbing around IIS already.

However, I'm also having trouble finding out how to enumerate the Roles/Services at all, so if there's a solution that involves doing that, it would certainly be useful, and much better than checking the side effect of having the ASPNET trace provider lying around.

Unfortunately, if you don't check the ASP.NET button, you can still get the ManagedEngine module in the IIS applicationHost.config file, so it's not a reliable check. You can also have ASP.NET mapped as an isapi filter, so checking them isn't enough. These things are especially problematic in the case where ASP.NET was installed but has been removed.

It looks like the best solution would be to examine the Role Services. However, API information on this is looking pretty rare, hence the cry for help.

5
  • Is this a console/windows forms app or from an IIS app itself? Do you mean in a specific site or just generally?
    – Kev
    Dec 14, 2010 at 13:06
  • The detection is from a winforms app.
    – Jim T
    Dec 14, 2010 at 13:37
  • The detection needs to be done generally. Basically, if the ASP.NET Role Service is removed, that's a server wide setting, I'm after a reliable way to detect that condition.
    – Jim T
    Dec 14, 2010 at 13:38
  • What is the intent here?
    – jcolebrand
    Dec 14, 2010 at 14:30
  • Ok, more explicitly, the intent is to guide the user as to what aspects the software requires to be configured on the server, and whether those aspects have been configured or not. ASP.NET is one of many modules being checked, including whether IIS is available at all, BITS and even time synchronisation. Only ASP.NET is proving elusive. It's a first blush common problem finder.
    – Jim T
    Dec 14, 2010 at 16:07

3 Answers 3

16

The absolute way to know if they checked that or not is to search the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components

In there you should see two values set to 1, ASPNET and NetFxEnvironment and NetFxExtensibility. This registry key is the IIS Setup key that contains all the components that have been enabled in IIS.

0
2

Determining if asp.net is even an installed feature (prerequisite for enabling it) can be done through PowerShell, which implies there is .net api out there for it if you dig hard enough. The PowerShell methods:

Import-Module servermanager
Get-WindowsFeature web-asp-net

Which will return an object of type Microsoft.Windows.ServerManager.Commands.Feature. The installed property is boolean and indicates whether or not the feature is installed.

1
  • anybody know how to reflect that or get the assembly it's in for reflecting? Also, looks like going to SF was a good idea.
    – jcolebrand
    Dec 14, 2010 at 19:13
0

So do you want the easy way? Make a nice pretty .aspx page that displays as HTML with an error block in a div in a placeholder saying "You need to install ASP.NET" and have it change on ASP.NET being installed to instead say "ASP.NET is installed" and then just have the tool launch this webpage in the default browser after copying it to the directory identified in IIS as the *:80 site (or create the directory mapping in IIS programmatically by altering the XML and then removing it later)

May not be the most elegant but it does ensure that testing shows what features are truly installed versus what's in an XML file.


Because that will scream "do it the lazy ignorant way" I'll remind you that the only way for me to know in javascript what features I can use is to test them before I try to use them, or assume they're there and watch it blow up. My point is, it doesn't matter what gets reported in a file, it matters what you can actually use. Just because C:\Windows\Micrsoft.Net\Framework\v3.xxxxxxxx exists and has files doesn't mean the dll's are registered in the GAC, does it?

4
  • I'm not keen on this. I'm really looking for a specific "this component is missing" test rather than setting up an end-to-end check, programatically, in the background, without asking the user, correctly working out all the urls necessary, etc. Corrupted installs are definitely a problem, but I'm much more interested in looking for missing components. For my purposes, checking if the .net3 folder exists is more than sufficient.
    – Jim T
    Dec 14, 2010 at 16:31
  • Well like I said that was the lazy easy way. Have you tried doing a snapshot of the applicationHost.config before and after ASP.NET installed on a clean machine in a VM?
    – jcolebrand
    Dec 14, 2010 at 16:34
  • Yes, I've done a diff between the two config files and the only thing that's at all reliable are the two settings mentioned in the question. I've updated the question with more specific details.
    – Jim T
    Dec 14, 2010 at 17:03
  • Thanks for the updates. I think that makes it slightly clearer. Also, I have no clue. Gonna ponder this for a moment.
    – jcolebrand
    Dec 14, 2010 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.