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

99封情书 提交于 2019-12-10 14:56:56

问题


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();

回答1:


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



回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/4914097/iis-6-0-programmatically-problem-creating-virtual-directories-and-not-setting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!