3

I've been asked to write a tool that detects all the requirements and tells the user whether the machine meets all of the requirements or not to be able install the different software solutions the company I'm interning at developed.

I need to check if WCF3 and ASP.NET are registered to IIS correctly, The code is written in C#. I need a bulletproof way to know if it's correctly registered or not.

Zak Soliman
  • 1,130
  • 1
  • 7
  • 14

2 Answers2

2

Check this thread: Programatically create a web site in IIS using C# and set port number if you're using IIS 7 you can programmatically access all registered sites. Keeping in mind the thread I provided discusses how to add a site programmatically, you should be able to use the "sites" collection to access all registered services and search for those by name or by other criteria (you'd have to check what properties are available).

ServerManager iisManager = new ServerManager();
iisManager.Sites; //Use this collection to find the services you need to know exist

It's also important to note that if you're interested in the application pool as well you'd access them like so:

ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

Finally, your application will need to run under an account with the appropriate permissions to read this information.

Community
  • 1
  • 1
alan
  • 6,705
  • 9
  • 40
  • 70
1

use ServiceHostFactory, After the factory constructs the ServiceHost

protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
  var hostname = base.CreateServiceHost(serviceType, baseAddresses);
  hostname.Extensions.Add(new CustomConfigurer());
  return hostname;
}

or you can use HttpContext

private string ConnectionString()
        {
            if (HttpContext.Current!=null)
                return ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
            else
                return GetConnectionStringFromRegistry();
        }
Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70