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:
DirectoryEn开发者_高级运维tries 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();
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" >
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
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.
- MSDN: IISApp Interface
- MSDN: IISApp2 Interface
精彩评论