我在 IIS 7.0 中遇到了一个奇怪的问题:
并且在 IIS 中的虚拟目录上仅启用了 Windows 身份验证模式
现在,如果我尝试以这种方式为 TestV/Folder/file.aspx 获取关联的 DirectoryEntry:
string vDir = @"/TestV/folder/file.aspx";
DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT" + vDir, @"adminusername", @"password");
dir.AuthenticationType = AuthenticationTypes.Secure;
try
{
Console.WriteLine(dir.Name);
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
Console.WriteLine("");
我得到异常:“系统找不到指定的路径”
现在,如果我回到 IIS,然后执行以下步骤:右键单击 TestV/Folder并启用匿名身份验证模式,然后再次禁用它
右键单击 TestV/Folder/file.aspx并启用匿名身份验证模式,然后再次禁用它
本质上,我只是对 aspx 文件 Testv/Folder/file.aspx 执行了一些手动访问。
经过上述步骤,如果我重新运行程序,代码成功地能够访问目录条目并成功打印名称(file.aspx)
这里有什么问题?
还有一个信息:
我在 IIS 6.0 上也看到了这种行为。因此,除非我在 IIS 中对虚拟目录中的文件夹/文件进行一些手动操作,否则它似乎不会在活动目录中创建相应的元数据?