【问题标题】:Getting Web Site Name from Web Project Setup从 Web 项目设置中获取网站名称
【发布时间】:2009-12-16 13:22:29
【问题描述】:

我正在为 WCF net-tcp 服务创建一个安装项目。我遇到的一件事是我需要更改“网站->管理应用程序->高级设置->启用的协议”。也可以使用命令行来完成:

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

问题出在自定义操作中,我可以获得 [TARGETSITE],但它的值是“/LM/W3SVC/2”(我也有 [TARGETVDIR])。问题是如何获取网站名称或如何使用 [TARGETSITE] 设置启用应用程序的协议?

【问题讨论】:

    标签: visual-studio visual-studio-2008 iis


    【解决方案1】:

    我结束的解决方案涉及将 metabasePath 转换为站点名称,然后使用 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;
    }
    

    要使用它,您必须参考:

    C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll
    C:\Windows\System32\inetsrv\Microsoft.Web.Management.dll
    

    【讨论】:

    • 其实我发现VS2008和VS2010 Beta 2中的Web Setup项目不支持IIS7接口。他们通过 IIS6 兼容性扩展部署您的应用程序,因此使用 IIS6 接口编写您自己的扩展也是安全的(直到支持 IIS7)
    猜你喜欢
    • 1970-01-01
    • 2018-06-26
    • 2010-12-11
    • 2014-02-09
    • 2012-04-12
    • 2014-07-30
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多