So I am creating a virtual directory in IIS 6.0 programmically, but I am following the only MSDN (or other) documentation on creating a virtual directory, but the documentation I have at
http://msdn.microsoft.com/en-us/library/ms525598(VS.90).aspx
Is causing my virtual directory to be an application in IIS. I was trying to use the metabase properties page:
But in the sea of options I am not sure what properties I need to set to stipulate it strictly as a virtual directory:
DirectoryEntries vdirs = site.Children;
DirectoryEntry newVDir = vdirs.Add(vDirName, (className.Replace("Service", "VirtualDir")));
newVDir.Properties["Path"][0] = phyPath;
newVDir.Properties["AccessScript"][0] = true;
newVDir.Properties["AppFriendlyName"][0] = vDirName;
newVDir.Properties["AppIsolated"][0] = "0";
newVDir.Properties["AppRoot"][0] = "/LM" + metaBaseFullPath.Substring(metaBaseFullPath.IndexOf("/", ("IIS://".Length)));
newVDir.CommitChanges();
Try not setting the app-pool specific entries. so just:
newVDir.Properties["Path"][0] = phyPath;
newVDir.Properties["AccessScript"][0] = true;
newVDir.CommitChanges();
Haven't done this in awhile, but i think thats it
The metabase.xml
file in %systemroot%\\windows\\system32\\inetsrv
is your best friend. If you create a virtual directory in IIS MMC you can see the requisite attributes attributes you need to set:
Here I created a virtual directory called myvdir
in a site, this is the metabase configuration persisted to metabase.xml
:
<IIsWebVirtualDir
Location ="/LM/W3SVC/1/root/myvdir"
AccessFlags="AccessRead | AccessScript"
DirBrowseFlags="DirBrowseShowDate | DirBrowseShowTime |
DirBrowseShowSize | DirBrowseShowExtension |
DirBrowseShowLongDate | EnableDefaultDoc"
Path="D:\websites\myapp\www\myvdir" >
As far as I remember, you cannot set an IIsWebVirtualDir to be an application (or not) by properties, but by calling methods on it. In your case you would have to call "AppDelete".
newVDir.Invoke("AppCreate", 1);
or
newVDir.Invoke("AppCreate2", new object[] { 0 });
newVDir.Invoke("AppDelete");
Details about these methods and their parameters can be found at the ADSI documentation, but you have to convert the code samples there to C# syntax.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.