views:

144

answers:

1

I'm creating a setup project for WCF net-tcp service. One thing I came across is that I need to change "Web Site->Manage Application->Advanced settings->Enabled Protocols". It can be also done using command line:

%windir%\system32\inetsrv\appcmd.exe set app "[Web Site Name]/[Applicaiton Name]" /enabledProtocols:http,net.tcp

The problem is in custom action I can get [TARGETSITE] but it's value is "/LM/W3SVC/2" (I have [TARGETVDIR] too). The question is how can I get Web Site Name or how can I use [TARGETSITE] to set application enabled protocols?

A: 

The solution I ended with involves converting metabasePath to site name and then using appcmd:

private static string GetSiteName(string metabasePath)
{
    var siteIdString = metabasePath.Substring(metabasePath.LastIndexOf("/") + 1);
    long siteId;
    long.TryParse(siteIdString, out siteId);

    if (siteId != 0)
    {
     var iisManager = new ServerManager();
     var config = iisManager.GetApplicationHostConfiguration();
     var sites = config.GetSection("system.applicationHost/sites").GetCollection();

     ConfigurationElement selectedSite = null;
     foreach (var site in sites)
     {
      if ((long)site.GetAttribute("id").Value == siteId)
       selectedSite = site;
     }

     if (selectedSite != null)
     {
      return selectedSite.GetAttribute("name").Value as string;
     }
    }

    return null;
}

To use this you will have to reference:

C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll
C:\Windows\System32\inetsrv\Microsoft.Web.Management.dll
Sergej Andrejev
Actually I found out that Web Setup project in VS2008 and VS2010 Beta 2 doesn't support IIS7 interfaces. They deploy your application through IIS6 compatibility extensions so it is safe to use IIS6 interface to write you own extensions too (until IIS7 is supported)
Sergej Andrejev