PhobiaDHS
asked on
How to programmatically detect .NET version assigned to an application pool in IIS 6,7, and 7.5?
Hey there everyone. I am working on a project that requires me to detect the .NET version that is assigned to an application pool. The project is being written in C++ with a few C# areas but can call any number of other files or languages if there is a need. The only thing is, everything that it calls has to be available on a standard web server installation of Windows 2003(R2), 2008 and 2008R2.
We found a VBScript file that works somewhat well on Windows 2003, but we would much prefer to avoid this and use an ADSI call or something similar. The problem is that ADSI doesn't have the capabilities to do what we are trying to make it do.
Please let me know if you need any other information in order to provide a possible answer.
Thanks a bunch everyone.
We found a VBScript file that works somewhat well on Windows 2003, but we would much prefer to avoid this and use an ADSI call or something similar. The problem is that ADSI doesn't have the capabilities to do what we are trying to make it do.
Please let me know if you need any other information in order to provide a possible answer.
Thanks a bunch everyone.
for example to assign .net v2.0 to application pool "DefaultAppPool":
appcmd.exe set config -section:system.applicatio nHost/appl icationPoo ls /+"[name='DefaultAppPool', managedRun timeVersio n='v2.0]" /commit:apphost
or using C#:
appcmd.exe set config -section:system.applicatio
or using C#:
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample {
private static void Main() {
using(ServerManager serverManager = new ServerManager()) {
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
ConfigurationElement addElement = applicationPoolsCollection.CreateElement("add");
addElement["name"] = @"DefaultAppPool";
addElement["managedRuntimeVersion"] = @"v2.0";
applicationPoolsCollection.Add(addElement);
serverManager.CommitChanges();
}
}
}
ASKER
As the answer applied to a different question, I would like to suggest closing with no points assigned.
ASKER
As the answer applied to a different question, I would like to suggest closing with no points assigned.
ASKER
What I mean is that per my understanding of the code given for the solution, the solution doesn't allow detection of the .NET version assigned to an app pool. It allows you to set it. If I am incorrect on this, please split and assign. My current understanding is that this does not apply to the question that was asked.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can detect this configuration by using the following as well:
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
string ver = applicationPoolsCollection.ChildElements[0].Attributes["managedRuntimeVersion"].Value.ToString();
}
ASKER
I have tested this and it works like a champ. Sorry for the confusion and thanks for following up with the extra information.
@PhobiaDHS
no problem :)
no problem :)
for both options check the following post:
http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/applicationPoolDefaults