Manage Application->Advanced settings->Enabled Protocols\". It can be also done usin" />
开发者

Getting Web Site Name from Web Project Setup

开发者 https://www.devze.com 2022-12-14 16:33 出处:网络
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 usin

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开发者_StackOverflow中文版 I get Web Site Name or how can I use [TARGETSITE] to set application enabled protocols?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号