MapPath 或在安装应用程序中使用的等效项

发布于 2024-10-03 21:16:06 字数 140 浏览 1 评论 0原文

我需要检查安装应用程序中的 .config 文件(WIX 项目中的 iis 自定义操作)。用户选择一个网站并输入虚拟目录名称。我无法执行 http 读取来检索配置文件,因为 ASP.NET 不提供配置文件。

如何找到所选网站和虚拟目录的本地磁盘路径?

I need to check a .config file in an installation application (iis custom action in a WIX project). The user picks a website and enters a virtual directory name. I can't do a http read to retrieve the config file as ASP.NET does not serve config files.

How can I find the local disk path of the selected website and virtual directory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落星ぅ辰 2024-10-10 21:16:06

经过进一步搜索,我最终使用了 DirectoryServices。我在这里为其他人发布我的解决方案。

如果还有更好的方法,欢迎留言。

    static string FindVirtualDirectoryPath(string virtualDirectoryName)
    {
        return FindVirtualDirectoryPath(null, virtualDirectoryName);
    }

    static string FindVirtualDirectoryPath(string siteName, string virtualDirectoryName)
    {
        DirectoryEntry iis = new DirectoryEntry("IIS://localhost/W3SVC");
        foreach (DirectoryEntry index in iis.Children)
        {
            if (index.SchemaClassName == "IIsWebServer")
            {
                int id = Convert.ToInt32(index.Name);
                DirectoryEntry site = new DirectoryEntry(string.Concat("IIS://localhost/W3SVC/", id));
                string iSiteName = site.Properties["ServerComment"].Value.ToString();
                if (iSiteName == siteName || (string.IsNullOrEmpty(siteName) && id == 1))
                {
                    DirectoryEntry rootVDir = new DirectoryEntry(string.Concat("IIS://localhost/W3SVC/", id, "/Root"));
                    foreach (DirectoryEntry vDir in rootVDir.Children)
                    {
                        if (vDir.SchemaClassName == "IIsWebVirtualDir" && vDir.Name.ToLower() == virtualDirectoryName.ToLower())
                        {
                            return vDir.Properties["Path"].Value.ToString();
                        }
                    }
                }
            }
        }
        return null;
    }

After further searching, I ended up using DirectoryServices. I'm posting my solution here for others.

If there is a better way, please still post it.

    static string FindVirtualDirectoryPath(string virtualDirectoryName)
    {
        return FindVirtualDirectoryPath(null, virtualDirectoryName);
    }

    static string FindVirtualDirectoryPath(string siteName, string virtualDirectoryName)
    {
        DirectoryEntry iis = new DirectoryEntry("IIS://localhost/W3SVC");
        foreach (DirectoryEntry index in iis.Children)
        {
            if (index.SchemaClassName == "IIsWebServer")
            {
                int id = Convert.ToInt32(index.Name);
                DirectoryEntry site = new DirectoryEntry(string.Concat("IIS://localhost/W3SVC/", id));
                string iSiteName = site.Properties["ServerComment"].Value.ToString();
                if (iSiteName == siteName || (string.IsNullOrEmpty(siteName) && id == 1))
                {
                    DirectoryEntry rootVDir = new DirectoryEntry(string.Concat("IIS://localhost/W3SVC/", id, "/Root"));
                    foreach (DirectoryEntry vDir in rootVDir.Children)
                    {
                        if (vDir.SchemaClassName == "IIsWebVirtualDir" && vDir.Name.ToLower() == virtualDirectoryName.ToLower())
                        {
                            return vDir.Properties["Path"].Value.ToString();
                        }
                    }
                }
            }
        }
        return null;
    }
橘味果▽酱 2024-10-10 21:16:06

您是否尝试过使用标准 WiX IIsExtension 来实现此目的?只需捕获属性中的用户输入,然后使用标准元素,例如 iis:WebSiteiis:WebVirtualDir 在适当的网站中创建虚拟目录。

Have you tried using the standard WiX IIsExtension for this? Just capture the user input in a property, and then use standard elements like iis:WebSite and iis:WebVirtualDir to create a virtual directory in appropriate web site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文