I am facing a weird issue in IIS 7.0:
我在IIS 7.0中面临一个奇怪的问题:
I have the following virtual directory in IIS: alt text http://i39.tinypic.com/4iijbb.jpg
我在IIS中有以下虚拟目录:alt text http://i39.tinypic.com/4iijbb.jpg
and only Windows Authentication mode is enabled on the virtual directory in IIS
并且在IIS中的虚拟目录上仅启用了Windows身份验证模式
Now if I try to get associated DirectoryEntry for TestV/Folder/file.aspx in this manner:
现在,如果我尝试以这种方式为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("");
I get the exception: "The system cannot find the path specified"
我得到异常:“系统找不到指定的路径”
Now if I go back to IIS and then perform the following steps: Right click on TestV/Folder and enable Anonymous authentication mode and then disable it again
现在,如果我返回IIS然后执行以下步骤:右键单击TestV / Folder并启用匿名身份验证模式,然后再次禁用它
Right click on TestV/Folder/file.aspx and enable Anonymous authentication mode and then disable it again
右键单击TestV / Folder / file.aspx并启用匿名身份验证模式,然后再次禁用它
Essentially i just performed some manual access on the aspx file Testv/Folder/file.aspx.
基本上我只是在aspx文件Testv / Folder / file.aspx上执行了一些手动访问。
After the above steps if i re run the program, the code is successfully able to access the directory entry and successfully prints the name (file.aspx)
完成上述步骤后,如果我重新运行程序,代码就能成功访问目录条目并成功打印名称(file.aspx)
What is the problem here?
这里有什么问题?
One more information:
还有一个信息:
I see this behavior on IIS 6.0 also. So it appears like until and unless I do some manual operation in IIS for a folder/file in virtual directory, it does not create the corresponding metadata in the active directory?
我在IIS 6.0上也看到了这种行为。所以看起来除非我在IIS中对虚拟目录中的文件夹/文件进行一些手动操作,否则它不会在活动目录中创建相应的元数据?
3 个解决方案
#1
I got the answer to the problem (with some help from one of my colleagues)
我得到了问题的答案(在我的一位同事的帮助下)
Here is the solution: 1. The program needs to add (pseudo?)entries to the IIS metadata before it access the file/folder under the virtual directory, before we access the entry:
解决方案如下:1。在访问条目之前,程序需要在访问虚拟目录下的文件/文件夹之前向IIS元数据添加(伪?)条目:
try
{
// make pseudo entries:
DirectoryEntry folder = rootDir.Children.Add("Folder", "IISWebDirectory");
folder.CommitChanges();
file = folder.Children.Add("File.aspx", "IISWebFile");
file.CommitChanges();
}
Then voila it works
瞧它有效
PS:
DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT" + vDir, @"adminusername", @"password");
dir.AuthenticationType = AuthenticationTypes.Secure;
dir.RefreshCache();
Directory.Refresh does not help
Directory.Refresh没有帮助
#2
Does it help if you call RefreshCache() right after the third line?
如果你在第三行之后调用RefreshCache()会有帮助吗?
DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT" + vDir, @"adminusername", @"password");
dir.AuthenticationType = AuthenticationTypes.Secure;
dir.RefreshCache();
#3
While this isn't exactly an answer I would point out that System.DirectoryServices is not generally used to interact with IIS. While it can give you access to IIS settings, WMI is generally a better choice.
虽然这不是一个答案,但我会指出System.DirectoryServices通常不用于与IIS交互。虽然它可以让您访问IIS设置,但WMI通常是更好的选择。
#1
I got the answer to the problem (with some help from one of my colleagues)
我得到了问题的答案(在我的一位同事的帮助下)
Here is the solution: 1. The program needs to add (pseudo?)entries to the IIS metadata before it access the file/folder under the virtual directory, before we access the entry:
解决方案如下:1。在访问条目之前,程序需要在访问虚拟目录下的文件/文件夹之前向IIS元数据添加(伪?)条目:
try
{
// make pseudo entries:
DirectoryEntry folder = rootDir.Children.Add("Folder", "IISWebDirectory");
folder.CommitChanges();
file = folder.Children.Add("File.aspx", "IISWebFile");
file.CommitChanges();
}
Then voila it works
瞧它有效
PS:
DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT" + vDir, @"adminusername", @"password");
dir.AuthenticationType = AuthenticationTypes.Secure;
dir.RefreshCache();
Directory.Refresh does not help
Directory.Refresh没有帮助
#2
Does it help if you call RefreshCache() right after the third line?
如果你在第三行之后调用RefreshCache()会有帮助吗?
DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT" + vDir, @"adminusername", @"password");
dir.AuthenticationType = AuthenticationTypes.Secure;
dir.RefreshCache();
#3
While this isn't exactly an answer I would point out that System.DirectoryServices is not generally used to interact with IIS. While it can give you access to IIS settings, WMI is generally a better choice.
虽然这不是一个答案,但我会指出System.DirectoryServices通常不用于与IIS交互。虽然它可以让您访问IIS设置,但WMI通常是更好的选择。