使用c 建立虛擬目錄

2021-04-12 13:10:00 字數 1979 閱讀 2542

const string constiiswebsiteroot = "iis://localhost/w3svc/1/root";

string virtualdirname = "virtualname";//虛擬目錄名稱

string physicalpath = @"c:/1";

directoryentry root = new directoryentry(constiiswebsiteroot);

directoryentry tbentry = root.children.add(virtualdirname, root.schemaclassname);

tbentry.properties["path"][0] = physicalpath;

tbentry.properties["accessread"][0] = false;   

tbentry.properties["contentindexed"][0] = true; ;

tbentry.properties["defaultdoc"][0] = "index.asp,default.aspx";

tbentry.properties["accessscript"][0] = true;

tbentry.properties["dontlog"][0] = true;

tbentry.properties["authflags"][0] = 0;

tbentry.properties["authflags"][0] = 1;

tbentry.commitchanges();

現在來解釋一下這段**:

建立虛擬目錄需要使用system.directoryentries命名空間下的directoryentry類

首先宣告乙個direcotryentry的例項

directoryentry root = new directoryentry(constiiswebsiteroot);

其中的引數constiiswebsiteroot由一下幾個部分組成

"iis://"+domainname+"/w3svc"+websitenumber+"/root"

websitenumber由你要在哪個站點建立虛擬目錄來決定,xp只能有乙個站點,所以websitenumber值為1,win2000server 和win2003可以建立多個站點,所以websitenumber的值可以大於1

然後建立direcotryentry例項的子節點  ,也就是要建立的虛擬目錄

directoryentry tbentry = root.children.add(virtualdirname, root.schemaclassname);

root.children.add(string namespace,string schemaclassname)方法會建立並返回乙個directoryentry的例項

下面的部分就是對這個新建立的節點進行操作了

tbentry.properties["path"][0] = physicalpath;    //設定虛擬目錄指向的物理路徑

tbentry.properties["accessread"][0] = false;     //設定讀取許可權

tbentry.properties["defaultdoc"][0] = "index.asp,default.aspx"; //設定預設文件,多值情況下中間用逗號分割

tbentry.properties["authflags"][0] = 0;   //    設定目錄的安全性,0表示不允許匿名訪問,1為允許,3為基本身份驗證,7為windows繼承身份驗證

tbentry.commitchanges();//

這裡這是列舉了部分屬性,如果得到更多屬性的資訊可是訪問direcotryentry.properties屬性

下面的方法是得到所有屬性名稱的方法:

foreach (propertyvaluecollection pvc in tbentry.properties)

使用c 建立虛擬目錄

最近在csdn論壇裡看見的一片偏關於使用.net 建立虛擬目錄的帖子,以前一直以為不能用託管 實現這個功能.在此總結一下 下面是建立虛擬目錄的 const string constiiswebsiteroot iis localhost w3svc 1 root string virtualdirn...

建立虛擬目錄

function criadiretoriovirtual byval vdirname as string,byval serverid as string,byval vdirpath as boolean as directoryentry dim newvdir as directoryen...

xampp apache建立虛擬目錄

1 用記事本開啟c windows system32 drivers etc hosts檔案,配置如下 127.0.0.1 phptest 注,如果在瀏覽器位址列輸入phptest被搜尋引擎導航到搜尋頁,請在前面加http 2 xampp control panel apache config ht...