gpt4 book ai didi

iis-7 - 使用 WMI 用 C# 创建 IIS 应用程序目录

转载 作者:行者123 更新时间:2023-12-03 21:39:55 25 4
gpt4 key购买 nike

我们有一个安装在 Windows 2003 和 Windows 2008 系统上的 Web 应用程序。过去,我们的安装代码使用 ADSI 在 IIS 中创建几个应用程序目录,但这需要在 Windows 2008 中安装 IIS 6 管理组件。我一直在尝试使用 WMI 创建应用程序目录,以便我们可以支持两个操作系统。

我一直在尝试这个代码

   public static void AddVirtualFolder(string serverName, string websiteId, string name, string path)
{
ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", serverName));
scope.Connect();

string siteName = string.Format("W3SVC/{0}/Root/{1}", websiteId, name);

ManagementClass mc = new ManagementClass(scope, new ManagementPath("IIsWebVirtualDirSetting"), null);
ManagementObject oWebVirtDir = mc.CreateInstance();

oWebVirtDir.Properties["Name"].Value = siteName;
oWebVirtDir.Properties["Path"].Value = path;
oWebVirtDir.Properties["AuthFlags"].Value = 5; // Integrated Windows Auth.
oWebVirtDir.Properties["EnableDefaultDoc"].Value = true;
// date, time, size, extension, longdate ;
oWebVirtDir.Properties["DirBrowseFlags"].Value = 0x4000003E;
oWebVirtDir.Properties["AccessFlags"].Value = 513; // read script
oWebVirtDir.Put();

ManagementObject mo = new ManagementObject(scope, new System.Management.ManagementPath("IIsWebVirtualDir='" + siteName + "'"), null);
ManagementBaseObject inputParameters = mo.GetMethodParameters("AppCreate2");
inputParameters["AppMode"] = 2;
mo.InvokeMethod("AppCreate2", inputParameters, null);
mo = new ManagementObject(scope, new System.Management.ManagementPath("IIsWebVirtualDirSetting='" + siteName + "'"), null);
mo.Properties["AppFriendlyName"].Value = name;
mo.Put();
}
}

但是,我在已知目录上发现路径未找到错误。如果有人有一些我可以使用的引用资料,我将不胜感激。也欢迎任何有关如何解决此问题的其他建议。

最佳答案

使用上面的代码,您仍然需要 Windows 2008/IIS7 上的 IIS6 兼容性位。这样做的原因是设置属性的调用,例如 DirBrowseFlags , AccessFlags等等是 IIS 6 元数据库属性,在没有 IIS6 管理组件的情况下,IIS7 不支持这些属性。

对于 IIS7,我建议直接针对 Microsoft.Web.Administration 进行编程。命名空间,但如果你真的需要使用 WMI,那么请参阅这篇文章:

Managing Sites with IIS 7.0's WMI Provider (IIS.NET)

关于iis-7 - 使用 WMI 用 C# 创建 IIS 应用程序目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2119511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com