简体   繁体   中英

IIS 6.0 programmatically - Problem creating virtual directories AND not setting it as a Application

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:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/cde669f1-5714-4159-af95-f334251c8cbd.mspx?mfr=true

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".

Make an IIsWebVirtualDir an application ...

newVDir.Invoke("AppCreate", 1);

or

newVDir.Invoke("AppCreate2", new object[] { 0 });

End an IIsWebVirtualDir being an application ...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM