尝试创建“虚拟目录”创建“虚拟应用程序”反而

发布于 2024-12-29 05:59:29 字数 1479 浏览 0 评论 0原文

我有一个 Web 应用程序,在其 IIS 虚拟应用程序下部署了两个虚拟目录。在 IIS 6 机器上,以下代码按预期创建这些虚拟目录,但是在 IIS 7 机器上,我最终得到的虚拟应用程序下面有两个其他虚拟应用程序,而不是一个虚拟应用程序下面有两个虚拟目录。我尝试了以下两种方法,但两者仍然创建虚拟应用程序,而不是虚拟目录。如何更改此代码以部署所需的虚拟目录,而不是不需要的虚拟应用程序?

一:

private void AddVirtualDir(DirectoryEntry entry)
{
    DirectoryEntry virtualDirectory = (DirectoryEntry)entry.Invoke("Create", "IIsWebVirtualDir", "VirtualDirectory");
    virtualDirectory.InvokeSet("Path", @"VirtualPath");
    virtualDirectory.InvokeSet("AppFriendlyName", "VirtualDirectory");
    virtualDirectory.Properties["AccessRead"][0] = true;
    virtualDirectory.Properties["AccessScript"][0] = 512;
    virtualDirectory.Properties["AppIsolated"].Clear();
    virtualDirectory.Properties["AppIsolated"].Add(2);
    virtualDirectory.Invoke("AppCreate", false);
    virtualDirectory.CommitChanges();
    entry.CommitChanges();
}

二:

private void AddVirtualDir(DirectoryEntry entry)
{
    var virtualDirectory = entry.Children.Add("VirtualDirectory", "IIsWebVirtualDir");
    virtualDirectory.Properties["AccessRead"][0] = true;
    virtualDirectory.Properties["AccessScript"][0] = 512;
    virtualDirectory.Properties["AppFriendlyName"][0] = "EditorControls";
    virtualDirectory.Properties["AppIsolated"][0] = 2;
    virtualDirectory.Properties["Path"][0] = Path.Combine(_INSTALLDIR, @"Kryptiq_Root\FormManagement\EditorControls");
    virtualDirectory.CommitChanges();
    entry.CommitChanges();
}

I have a web application that deploys with two virtual directories under it's IIS virtual application. On IIS 6 boxes, the following code creates these virtual directories as expected, however on IIS 7 boxes, I end up with my virtual application having two other virtual applications under it, rather than one virtual application with two virtual directories under it. I've tried the following two methods, but both still create a virtual application, not a virtual directory. How can this code be changed to deploy the needed virtual directories, not the undesired virtual applications?

one:

private void AddVirtualDir(DirectoryEntry entry)
{
    DirectoryEntry virtualDirectory = (DirectoryEntry)entry.Invoke("Create", "IIsWebVirtualDir", "VirtualDirectory");
    virtualDirectory.InvokeSet("Path", @"VirtualPath");
    virtualDirectory.InvokeSet("AppFriendlyName", "VirtualDirectory");
    virtualDirectory.Properties["AccessRead"][0] = true;
    virtualDirectory.Properties["AccessScript"][0] = 512;
    virtualDirectory.Properties["AppIsolated"].Clear();
    virtualDirectory.Properties["AppIsolated"].Add(2);
    virtualDirectory.Invoke("AppCreate", false);
    virtualDirectory.CommitChanges();
    entry.CommitChanges();
}

two:

private void AddVirtualDir(DirectoryEntry entry)
{
    var virtualDirectory = entry.Children.Add("VirtualDirectory", "IIsWebVirtualDir");
    virtualDirectory.Properties["AccessRead"][0] = true;
    virtualDirectory.Properties["AccessScript"][0] = 512;
    virtualDirectory.Properties["AppFriendlyName"][0] = "EditorControls";
    virtualDirectory.Properties["AppIsolated"][0] = 2;
    virtualDirectory.Properties["Path"][0] = Path.Combine(_INSTALLDIR, @"Kryptiq_Root\FormManagement\EditorControls");
    virtualDirectory.CommitChanges();
    entry.CommitChanges();
}

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

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

发布评论

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

评论(1

花开雨落又逢春i 2025-01-05 05:59:29

这是如何在 IIS6 上工作的

这里的问题是您正在设置 AppIsolated 值。在 IIS6 中,它用于配置应用程序的运行方式,通常您不需要触及它或将其添加到任何地方。

AppIsolated 始终默认为 2,这意味着池化进程,即应用程序将在父应用程序的应用程序池或 AppPoolId

存在其他值的原因是,您可以将应用程序配置为在几种旧版 IIS5 模式下运行 - 进程内和进程外模式。

因此,除非您将网站的 /root 应用程序配置为以 AppIsolated="2" 以外的任何方式运行,否则无需设置此值。

您的代码可以如此简单:

using (var entry = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT"))
{
  using (DirectoryEntry virtualDirectory = entry.Children.Add("MyVdir", 
                                           "IIsWebVirtualDir"))
  {
    virtualDirectory.Properties["Path"][0] = PATH_TO_MY_STUFF;
    virtualDirectory.Properties["AccessRead"][0] = true;
    virtualDirectory.Properties["AccessScript"][0] = 512;
    virtualDirectory.CommitChanges();
  }
}

如果您在 IIS6 中设置了 AppIsolated ,它将被忽略,因为要使目录成为应用程序,您还需要设置 AppRoot

IIS7 - IIS6 兼容性填充程序

在 IIS7 中,当使用 System.DirectoryServices 时,您正在使用底层 II6 兼容性 API,该 API 会将这些 ADSI 调用转换为对新 IIS7 API 的调用。它并不完美,我怀疑当它看到 AppIsolated 被设置时,它假设您需要一个应用程序,尽管您没有指定任何其他与应用程序相关的元数据库值。

IIS7 托管 API 更好

您可能知道这一点,但最好通过托管 Microsoft.Web.Administration 位。并非所有 ADSI/元数据库兼容性设置在 IIS7 中都有等效设置,这可能会迫使转换层做出妥协来解决此问题。我在此处这里

How this works on IIS6

The problem here is that you're setting the AppIsolated value. In IIS6 this is used to configure how an application should run, and generally you should never need to touch this or add it anywhere.

AppIsolated always defaults to 2 which means pooled process, i.e. the application will run in either the parent application's application pool or in the pool specified by AppPoolId.

The reason that there are other values is so that you can configure an application to run in a couple of legacy IIS5 modes - In Process and Out of Process mode.

So unless you configured your site's /root application to run as anything other than AppIsolated="2" then you don't need to set this value.

Your code can be as simple as:

using (var entry = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT"))
{
  using (DirectoryEntry virtualDirectory = entry.Children.Add("MyVdir", 
                                           "IIsWebVirtualDir"))
  {
    virtualDirectory.Properties["Path"][0] = PATH_TO_MY_STUFF;
    virtualDirectory.Properties["AccessRead"][0] = true;
    virtualDirectory.Properties["AccessScript"][0] = 512;
    virtualDirectory.CommitChanges();
  }
}

If you do set AppIsolated in IIS6 it gets ignored because for the directory to become an application you also need to set AppRoot.

IIS7 - IIS6 compatibility shim

In IIS7 when using System.DirectoryServices you're working with an underlying II6 compatibility API which is translating these ADSI calls to calls to the new IIS7 API. It's not perfect and I suspect that when it see's AppIsolated being set it's assuming you want an application, despite you not specifying any other application related metabase values.

IIS7 Managed API is better

You probably know this, but it's better to work with IIS7 configuration via the managed Microsoft.Web.Administration bits. Not all of the ADSI/metabase compatibility settings have equivalents in IIS7 which can force the translation layer to make compromises to work around this. I mention these types of problems in my answers here and here.

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