会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
思想决定人生,态度改变一切
成功者找方法,失败者找借口! 做事先做人;安分做人,本分做事!
博客园
::
首页
::
博问
::
闪存
::
新随笔
::
联系
::
订阅
::
管理
::
公告
对虚拟目录的操作(转)
一、查看虚拟目录是否存在
private
bool
IsExitesVirtualDir(
string
virtualdirname)
{
bool
exited
=
false
;
DirectoryEntry _entry
=
new
DirectoryEntry(
"
IIS://localhost/W3SVC/1/Root
"
);
DirectoryEntries _entries
=
_entry.Children;
foreach
(DirectoryEntry _cen
in
_entries)
{
if
(_cen.Name
==
virtualdirname)
exited
=
true
;
}
return
exited;
}
其中virtualdirpath指要建立的虚拟目录名称;
二、新增虚拟目录
private
void
CreateVirtualDir(
string
virtualdirname,
string
logicDir)
{
if
(IsExitesVirtualDir(virtualdirname))
DeleteVirtualDir(virtualdirname);
DirectoryEntry _rootEntry ;
_rootEntry
=
new
DirectoryEntry(
"
IIS://localhost/W3SVC/1/root
"
);
DirectoryEntry _newVirDir;
_newVirDir
=
_rootEntry .Children.Add(virtualdirpath,
"
IIsWebVirtualDir
"
);
_newVirDir.Invoke(
"
AppCreate
"
,
true
);
_newVirDir.CommitChanges();
_rootEntry .CommitChanges();
_newVirDir.Properties[
"
AnonymousPasswordSync
"
][
0
]
=
true
;
_newVirDir.Properties[
"
Path
"
][
0
]
=
logicDir
+
@"
virtualdirentry\virtualname\
"
;
_newVirDir.CommitChanges();
}
_newVirDir.Properties[
"
Path
"
][
0
] 的值为虚拟目录对应的物理地址;
三、更新虚拟目录
public
void
Update(
string
virtualdirname)
{
//
判断需要更改的虚拟目录是否存在
if
(_IsExitesVirtualDir(virtualdirname))
{
DirectoryEntry _rootEntry ;
_rootEntry
=
new
DirectoryEntry(
"
IIS://localhost/W3SVC/1/root
"
);
DirectoryEntry ode
=
_rootEntry.Children.Find(virtualdirname,
"
IIsWebVirtualDir
"
);
UpdateDirInfo(ode);
}
}
private
void
UpdateDirInfo(DirectoryEntry de)
{
de.Properties[
"
AnonymousUserName
"
][
0
]
=
AnonymousUserName;
de.Properties[
"
AnonymousUserPass
"
][
0
]
=
AnonymousUserPass;
de.Properties[
"
AccessRead
"
][
0
]
=
boolen;
de.Properties[
"
AccessExecute
"
][
0
]
=
boolen;
de.Properties[
"
AccessWrite
"
][
0
]
=
boolen;
de.Properties[
"
AuthBasic
"
][
0
]
=
boolen;
de.Properties[
"
AuthNTLM
"
][
0
]
=
boolen;
de.Properties[
"
ContentIndexed
"
][
0
]
=
boolen;
de.Properties[
"
EnableDefaultDoc
"
][
0
]
=
boolen;
de.Properties[
"
EnableDirBrowsing
"
][
0
]
=
boolen;
de.Properties[
"
AccessSSL
"
][
0
]
=
boolen;
de.Properties[
"
AccessScript
"
][
0
]
=
boolen;
de.Properties[
"
DefaultDoc
"
][
0
]
=
DefaultDoc;
de.Properties[
"
Path
"
][
0
]
=
Path;
de.CommitChanges();
}
四、删除虚拟目录
private
void
DeleteVirtualDir(
string
virtualdirname)
{
DirectoryEntry _rootEntry ;
_rootEntry
=
new
DirectoryEntry(
"
IIS://localhost/W3SVC/1/root
"
);
object
[] paras
=
new
object
[
2
];
paras[
0
]
=
"
IIsVirtualDir
"
;
paras[
1
]
=
virtualdirname;
_rootEntry .Invoke(
"
Delete
"
,paras);
_rootEntry .CommitChanges();
}
posted on
2006-05-24 08:44
投石问路
阅读(
178
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部