|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我实在想不明白java的机制,为什么非要那么蛋疼,在同一个平台下重复编译。iis|假造目次网上找到本人实行,并收拾了一下:
全部背景文件以下:
usingSystem;
usingSystem.Data;
usingSystem.DirectoryServices;
usingSystem.Collections;
usingSystem.Threading;
namespaceAspcn.Management
{
///<summary>
///IISManager的择要申明。
///</summary>
publicclassIISManager
{
///<summary>
///使用程序的主出口点。
///</summary>
[STAThread]
staticvoidMain(string[]args)
{
IISManagertest=newIISManager();
test.Connect();
VirtualDirectoryvd=newVirtualDirectory();
vd.Path=@"c:Inetpubwwwroot项目文件夹称号";
vd.Name="BKDEIP/WEBUI/Mobile";
//if(test.Exists(vd.Name))
//{
//test.Delete(vd.Name);
//}
//else
//{
//test.Create(vd);
//}
test.Create(vd);
}
//界说必要利用的
privatestring_server,_website;
privateVirtualDirectories_virdirs;
protectedSystem.DirectoryServices.DirectoryEntryrootfolder;
privatebool_batchflag;
publicIISManager()
{
//默许情形下利用localhost,即会见当地机
_server="localhost";
_website="1";
_batchflag=false;
}
publicIISManager(stringstrServer)
{
_server=strServer;
_website="1";
_batchflag=false;
}
///<summary>
///界说大众属性
///</summary>
//Server属性界说会见呆板的名字,能够是IP与盘算名
publicstringServer
{
get{return_server;}
set{_server=value;}
}
//WebSite属性界说,为一数字,为便利,利用string
//一样平常来讲第一台主机为1,第二台主机为2,顺次类推
publicstringWebSite
{
get{return_website;}
set{_website=value;}
}
//假造目次的名字
publicVirtualDirectoriesVirDirs
{
get{return_virdirs;}
set{_virdirs=value;}
}
///<summary>
///界说大众办法
///</summary>
//毗连服务器
publicvoidConnect()
{
ConnectToServer();
}
//为便利重载
publicvoidConnect(stringstrServer)
{
_server=strServer;
ConnectToServer();
}
//为便利重载
publicvoidConnect(stringstrServer,stringstrWebSite)
{
_server=strServer;
_website=strWebSite;
ConnectToServer();
}
//判别是不是存这个假造目次
publicboolExists(stringstrVirdir)
{
return_virdirs.Contains(strVirdir);
}
//增加一个假造目次
publicvoidCreate(VirtualDirectorynewdir)
{
stringstrPath="IIS://"+_server+"/W3SVC/"+_website+"/ROOT/"+newdir.Name;
if(!_virdirs.Contains(newdir.Name)||_batchflag)
{
try
{
//到场到ROOT的Children汇合中往
DirectoryEntrynewVirDir=rootfolder.Children.Add(newdir.Name,"IIsWebVirtualDir");
newVirDir.Invoke("AppCreate",true);
newVirDir.CommitChanges();
rootfolder.CommitChanges();
//然后更新数据
UpdateDirInfo(newVirDir,newdir);
}
catch(Exceptionee)
{
thrownewException(ee.ToString());
}
}
else
{
thrownewException("Thisvirtualdirectoryisalreadyexist.");
}
}
//失掉一个假造目次
publicVirtualDirectoryGetVirDir(stringstrVirdir)
{
VirtualDirectorytmp=null;
if(_virdirs.Contains(strVirdir))
{
tmp=_virdirs.Find(strVirdir);
((VirtualDirectory)_virdirs[strVirdir]).flag=2;
}
else
{
thrownewException("Thisvirtualdirectoryisnotexists");
}
returntmp;
}
//更新一个假造目次
publicvoidUpdate(VirtualDirectorydir)
{
//判别必要变动的假造目次是不是存在
if(_virdirs.Contains(dir.Name))
{
DirectoryEntryode=rootfolder.Children.Find(dir.Name,"IIsWebVirtualDir");
UpdateDirInfo(ode,dir);
}
else
{
thrownewException("Thisvirtualdirectoryisnotexists.");
}
}
//删除一个假造目次
publicvoidDelete(stringstrVirdir)
{
if(_virdirs.Contains(strVirdir))
{
object[]paras=newobject[2];
paras[0]="IIsWebVirtualDir";//暗示操纵的是假造目次
paras[1]=strVirdir;
rootfolder.Invoke("Delete",paras);
rootfolder.CommitChanges();
}
else
{
thrownewException("Cantdelete"+strVirdir+",becauseitisntexists.");
}
}
//批量更新
publicvoidUpdateBatch()
{
BatchUpdate(_virdirs);
}
//重载一个:-)
publicvoidUpdateBatch(VirtualDirectoriesvds)
{
BatchUpdate(vds);
}
///<summary>
///公有办法
///</summary>
//毗连服务器
privatevoidConnectToServer()
{
stringstrPath="IIS://"+_server+"/W3SVC/"+_website+"/ROOT";
try
{
this.rootfolder=newDirectoryEntry(strPath);
_virdirs=GetVirDirs(this.rootfolder.Children);
}
catch(Exceptione)
{
thrownewException("Cantconnecttotheserver["+_server+"]...",e);
}
}
//实行批量更新
privatevoidBatchUpdate(VirtualDirectoriesvds)
{
_batchflag=true;
foreach(objectiteminvds.Values)
{
VirtualDirectoryvd=(VirtualDirectory)item;
switch(vd.flag)
{
case0:
break;
case1:
Create(vd);
break;
case2:
Update(vd);
break;
}
}
_batchflag=false;
}
//更新东东
privatevoidUpdateDirInfo(DirectoryEntryde,VirtualDirectoryvd)
{
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();
}
//猎取假造目次汇合
privateVirtualDirectoriesGetVirDirs(DirectoryEntriesdes)
{
VirtualDirectoriestmpdirs=newVirtualDirectories();
foreach(DirectoryEntrydeindes)
{
if(de.SchemaClassName=="IIsWebVirtualDir")
{
VirtualDirectoryvd=newVirtualDirectory();
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);
}
}
returntmpdirs;
}
}
///<summary>
///VirtualDirectory类
///</summary>
publicclassVirtualDirectory
{
privatebool_read,_execute,_script,_ssl,_write,_authbasic,_authntlm,_indexed,_endirbrow,_endefaultdoc;
privatestring_ausername,_auserpass,_name,_path;
privateint_flag;
privatestring_defaultdoc;
///<summary>
///机关函数
///</summary>
publicVirtualDirectory()
{
SetValue();
}
publicVirtualDirectory(stringstrVirDirName)
{
_name=strVirDirName;
SetValue();
}
privatevoidSetValue()
{
_read=true;_execute=false;_script=false;_ssl=false;_write=false;_authbasic=false;_authntlm=false;
_indexed=false;_endirbrow=false;_endefaultdoc=false;
_flag=1;
_defaultdoc="default.htm,default.aspx,default.asp,index.htm";
_path="C:";
_ausername="";_auserpass="";_name="";
}
///<summary>
///界说属性,IISVirtualDir太多属性了
///我只弄了对照主要的一些,别的的年夜伙必要的自个加吧。
///</summary>
publicintflag
{
get{return_flag;}
set{_flag=value;}
}
publicboolAccessRead
{
get{return_read;}
set{_read=value;}
}
publicboolAccessWrite
{
get{return_write;}
set{_write=value;}
}
publicboolAccessExecute
{
get{return_execute;}
set{_execute=value;}
}
publicboolAccessSSL
{
get{return_ssl;}
set{_ssl=value;}
}
publicboolAccessscript
{
get{return_script;}
set{_script=value;}
}
publicboolAuthBasic
{
get{return_authbasic;}
set{_authbasic=value;}
}
publicboolAuthNTLM
{
get{return_authntlm;}
set{_authntlm=value;}
}
publicboolContentIndexed
{
get{return_indexed;}
set{_indexed=value;}
}
publicboolEnableDirBrowsing
{
get{return_endirbrow;}
set{_endirbrow=value;}
}
publicboolEnableDefaultDoc
{
get{return_endefaultdoc;}
set{_endefaultdoc=value;}
}
publicstringName
{
get{return_name;}
set{_name=value;}
}
publicstringPath
{
get{return_path;}
set{_path=value;}
}
publicstringDefaultDoc
{
get{return_defaultdoc;}
set{_defaultdoc=value;}
}
publicstringAnonymousUserName
{
get{return_ausername;}
set{_ausername=value;}
}
publicstringAnonymousUserPass
{
get{return_auserpass;}
set{_auserpass=value;}
}
}
///<summary>
///汇合VirtualDirectories
///</summary>
publicclassVirtualDirectories:System.Collections.Hashtable
{
publicVirtualDirectories()
{
}
//增加新的办法
publicVirtualDirectoryFind(stringstrName)
{
return(VirtualDirectory)this[strName];
}
}
}
感谢浏览!
呵呵,那你就关注微软的招聘信息以及别人的招聘经验啊,还有也不一定去做技术的,你如果真的想去就多了解了解。(其实我的意思是说想到微软做技术是很不容易的。 |
|