国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > IIS > 正文

IIS控制管理(Web虛擬目錄的創(chuàng)建及管理)

2024-08-29 03:13:55
字體:
供稿:網(wǎng)友
(一)createwebdir.cs 使用示例

string sserver = "localhost";
string virtualdir = "bug2004"; //虛擬目錄
string pathdir = @"d:/mywebdirtest/bug2000" //物理目錄

iismanager iismg = new iismanager(sserver);
iismg.connect();

if (iismg.exists(virtualdir]))
{
console.write(virtualdir+ " is exist!");
}
else
{
myini.iniwritevalue("webdir","webdirexist","false");

iismg.get_anonymoususer();
string[] anonymoususer = new string[2];
anonymoususer[0] = iismg.anonymoususername ;
anonymoususer[1] = iismg.anonymoususerpass ;

virtualdirectory newvirdir = new virtualdirectory(virtualdir,pathdir,anonymoususer);
if (iismg.create(newvirdir))
console.write(virtualdir+ " 創(chuàng)建成功!");
else
console.write(virtualdir+ " 創(chuàng)建不成功!");
}

iismg.close();

(二)createwebdir.cs 是轉(zhuǎn)貼過來的,我作了些完善和修改

///***********************************************************
///************** iis控制管理類 **************
///************** 轉(zhuǎn)貼自: 飛刀 http://www.aspcn.com *************
///***********************************************************
using system;
using system.data;
using system.directoryservices;
using system.collections;

namespace createwebdir
{
/// <summary>
/// iismanager 的摘要說明。
/// </summary>
public class iismanager
{
//定義需要使用的
private string _server,_website,_anonymoususerpass,_anonymoususername;
private virtualdirectories _virdirs;
protected system.directoryservices.directoryentry rootfolder;
private bool _batchflag;
public iismanager()
{
//默認情況下使用localhost,即訪問本地機
_server = "localhost";
_website = "1";
_batchflag = false;
}
public iismanager(string strserver)
{
_server = strserver;
_website = "1";
_batchflag = false;
}
/// <summary>
/// 定義公共屬性
/// </summary>

public void get_anonymoususer()
{
_anonymoususerpass="iusr_deve-server";
_anonymoususername="iusr_deve-server";
virtualdirectory vdir;
try
{
hashtable mylist = (hashtable)_virdirs;
idictionaryenumerator myenumerator = mylist.getenumerator();
while ( myenumerator.movenext() )
{
vdir = (virtualdirectory)myenumerator.value;
if (vdir.anonymoususername!="" && vdir.anonymoususerpass != "")
{
_anonymoususername=vdir.anonymoususername;
_anonymoususerpass=vdir.anonymoususerpass;
break;
}
}
}
catch
{
_anonymoususerpass="iusr_deve-server";
_anonymoususername="iusr_deve-server";
}
}
public string anonymoususername
{
get{ return _anonymoususername;}
set{ _anonymoususername = value;}
}
public string anonymoususerpass
{
get{ return _anonymoususerpass;}
set{ _anonymoususerpass = value;}
}
//server屬性定義訪問機器的名字,可以是ip與計算名
public string server
{
get{ return _server;}
set{ _server = value;}
}
//website屬性定義,為一數(shù)字,為方便,使用string
//一般來說第一臺主機為1,第二臺主機為2,依次類推
public string website
{
get{ return _website; }
set{ _website = value; }
}

//虛擬目錄的名字
public virtualdirectories virdirs
{
get{ return _virdirs; }
set{ _virdirs = value;}
}
///<summary>
///定義公共方法
///</summary>

//連接服務(wù)器
public void connect()
{
connecttoserver();
}
//為方便重載
public void connect(string strserver)
{
_server = strserver;
connecttoserver();
}
//為方便重載
public void connect(string strserver,string strwebsite)
{
_server = strserver;
_website = strwebsite;
connecttoserver();
}
//判斷是否存這個虛擬目錄
public bool exists(string strvirdir)
{
return _virdirs.contains(strvirdir);
}
//添加一個虛擬目錄
public bool create(virtualdirectory newdir)
{
string strpath = "iis://" + _server + "/w3svc/" + _website + "/root/" + newdir.name;
if(!_virdirs.contains(newdir.name) || _batchflag )
{
try
{
//加入到root的children集合中去
directoryentry newvirdir = rootfolder.children.add(newdir.name,"iiswebvirtualdir");
newvirdir.invoke("appcreate",true);
newvirdir.commitchanges();
rootfolder.commitchanges();
//然后更新數(shù)據(jù)
updatedirinfo(newvirdir,newdir);
return true;
}
catch(exception ee)
{
//throw new exception(ee.tostring());
return false;
}
}
else
{
return true;
//throw new exception("this virtual directory is already exist.");
}
}
//得到一個虛擬目錄
public virtualdirectory getvirdir(string strvirdir)
{
virtualdirectory tmp = null;
if(_virdirs.contains(strvirdir))
{
tmp = _virdirs.find(strvirdir);
((virtualdirectory)_virdirs[strvirdir]).flag = 2;
}
else
{
//throw new exception("this virtual directory is not exists");
}
return tmp;
}

//更新一個虛擬目錄
public void update(virtualdirectory dir)
{
//判斷需要更改的虛擬目錄是否存在
if(_virdirs.contains(dir.name))
{
directoryentry ode = rootfolder.children.find(dir.name,"iiswebvirtualdir");
updatedirinfo(ode,dir);
}
else
{
//throw new exception("this virtual directory is not exists.");
}
}
 
//刪除一個虛擬目錄
public void delete(string strvirdir)
{
if(_virdirs.contains(strvirdir))
{
object[] paras = new object[2];
paras[0] = "iiswebvirtualdir"; //表示操作的是虛擬目錄
paras[1] = strvirdir;
rootfolder.invoke("delete",paras);
rootfolder.commitchanges();
}
else
{
//throw new exception("can''t delete " + strvirdir + ",because it isn''t exists.");
}
}
//批量更新
public void updatebatch()
{
batchupdate(_virdirs);
}
//重載一個:-)
public void updatebatch(virtualdirectories vds)
{
batchupdate(vds);
}
 
///<summary>
///私有方法
///</summary>

public void close()
{
_virdirs.clear();
_virdirs = null;
rootfolder.dispose();

}
//連接服務(wù)器
private void connecttoserver()
{
string strpath = "iis://" + _server + "/w3svc/" + _website +"/root";
try
{
this.rootfolder = new directoryentry(strpath);
_virdirs = getvirdirs(this.rootfolder.children);
}
catch(exception e)
{
//throw new exception("can''t connect to the server ["+ _server +"] ...",e);
}
}
//執(zhí)行批量更新
private void batchupdate(virtualdirectories vds)
{
_batchflag = true;
foreach(object item in vds.values)
{
virtualdirectory vd = (virtualdirectory)item;
switch(vd.flag)
{
case 0:
break;
case 1:
create(vd);
break;
case 2:
update(vd);
break;
}
}
_batchflag = false;
}
//更新東東
private void updatedirinfo(directoryentry de,virtualdirectory vd)
{
de.properties["anonymoususername"][0] = vd.anonymoususername;
de.properties["anonymoususerpass"][0] = vd.anonymoususerpass;
de.properties["accessread"][0] = vd.accessread;
de.properties["accessexecute"][0] = vd.accessexecute;
de.properties["accesswrite"][0] = vd.accesswrite;
de.properties["authbasic"][0] = vd.authbasic;
de.properties["authntlm"][0] = vd.authntlm;
de.properties["contentindexed"][0] = vd.contentindexed;
de.properties["enabledefaultdoc"][0] = vd.enabledefaultdoc;
de.properties["enabledirbrowsing"][0] = vd.enabledirbrowsing;
de.properties["accessssl"][0] = vd.accessssl;
de.properties["accessscript"][0] = vd.accessscript;
de.properties["defaultdoc"][0] = vd.defaultdoc;
de.properties["path"][0] = vd.path;
de.commitchanges();
}

//獲取虛擬目錄集合
private virtualdirectories getvirdirs(directoryentries des)
{
virtualdirectories tmpdirs = new virtualdirectories();
foreach(directoryentry de in des)
{
if(de.schemaclassname == "iiswebvirtualdir")
{
virtualdirectory vd = new virtualdirectory();
vd.name = de.name;
vd.accessread = (bool)de.properties["accessread"][0];
vd.accessexecute = (bool)de.properties["accessexecute"][0];
vd.accesswrite = (bool)de.properties["accesswrite"][0];
vd.anonymoususername = (string)de.properties["anonymoususername"][0];
vd.anonymoususerpass = (string)de.properties["anonymoususername"][0];
vd.authbasic = (bool)de.properties["authbasic"][0];
vd.authntlm = (bool)de.properties["authntlm"][0];
vd.contentindexed = (bool)de.properties["contentindexed"][0];
vd.enabledefaultdoc = (bool)de.properties["enabledefaultdoc"][0];
vd.enabledirbrowsing = (bool)de.properties["enabledirbrowsing"][0];
vd.accessssl = (bool)de.properties["accessssl"][0];
vd.accessscript = (bool)de.properties["accessscript"][0];
vd.path = (string)de.properties["path"][0];
vd.flag = 0;
vd.defaultdoc = (string)de.properties["defaultdoc"][0];
tmpdirs.add(vd.name,vd);
}
}
return tmpdirs;
}

}
/// <summary>
/// virtualdirectory類
/// </summary>
public class virtualdirectory
{
private bool _read,_execute,_script,_ssl,_write,_authbasic,_authntlm,_indexed,_endirbrow,_endefaultdoc;
private string _ausername,_auserpass,_name,_path;
private int _flag;
private string _defaultdoc;
/// <summary>
/// 構(gòu)造函數(shù)
/// </summary>
public virtualdirectory()
{
setvalue();
}
public virtualdirectory(string svirdirname)
{
setvalue();
_name = svirdirname;
}
// svirdirname:虛擬路徑;
// strphypath: 物理路徑( physics path)
public virtualdirectory(string svirdirname,string strphypath,string[] anonymoususer)
{
setvalue();
_name = svirdirname;
_path = strphypath;
_ausername = anonymoususer[0];
_auserpass = anonymoususer[1];
}
private void setvalue()
{
_read = true;_execute = false;_script = true;_ssl= false;_write=false;_authbasic=false;
_authntlm=true;_indexed = true;_endirbrow=false;_endefaultdoc = true;
_flag = 1;
_defaultdoc = "default.htm,default.aspx,default.asp,index.htm";
_path = "c://";
_ausername = "iusr_deve-server";_auserpass ="iusr_deve-server";_name="";
}
///<summary>
///定義屬性,iisvirtualdir太多屬性了
///我只搞了比較重要的一些,其它的大伙需要的自個加吧。
///</summary>

public int flag
{
get{ return _flag;}
set{ _flag = value;}
}
public bool accessread
{
get{ return _read;}
set{ _read = value;}
}
public bool accesswrite
{
get{ return _write;}
set{ _write = value;}
}
public bool accessexecute
{
get{ return _execute;}
set{ _execute = value;}
}
public bool accessssl
{
get{ return _ssl;}
set{ _ssl = value;}
}
public bool accessscript
{
get{ return _script;}
set{ _script = value;}
}
public bool authbasic
{
get{ return _authbasic;}
set{ _authbasic = value;}
}
public bool authntlm
{
get{ return _authntlm;}
set{ _authntlm = value;}
}
public bool contentindexed
{
get{ return _indexed;}
set{ _indexed = value;}
}
public bool enabledirbrowsing
{
get{ return _endirbrow;}
set{ _endirbrow = value;}
}
public bool enabledefaultdoc
{
get{ return _endefaultdoc;}
set{ _endefaultdoc = value;}
}
public string name
{
get{ return _name;}
set{ _name = value;}
}
public string path
{
get{ return _path;}
set{ _path = value;}
}
public string defaultdoc
{
get{ return _defaultdoc;}
set{ _defaultdoc = value;}
}
public string anonymoususername
{
get{ return _ausername;}
set{ _ausername = value;}
}
public string anonymoususerpass
{
get{ return _auserpass;}
set{ _auserpass = value;}
}
}
/// <summary>
/// 集合virtualdirectories
/// </summary>

public class virtualdirectories : system.collections.hashtable
{
public virtualdirectories()
{
}
//添加新的方法
public virtualdirectory find(string strname)
{
return (virtualdirectory)this[strname];
}
}
}

最大的網(wǎng)站源碼資源下載站,

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 庄浪县| 涿鹿县| 富源县| 灵寿县| 巴林左旗| 喀什市| 柯坪县| 清水县| 天等县| 靖远县| 乳山市| 望城县| 大姚县| 襄樊市| 林芝县| 罗甸县| 辉南县| 桂阳县| 九龙坡区| 广饶县| 正安县| 三穗县| 华容县| 鹤岗市| 屏南县| 克东县| 万宁市| 嵊州市| 文水县| 葵青区| 青浦区| 砚山县| 江口县| 永安市| 巩留县| 大姚县| 新田县| 井冈山市| 桂阳县| 巨鹿县| 庆云县|