zoukankan
html css js c++ java
对虚拟目录的操作(转)
一、查看虚拟目录是否存在
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();
}
作者:
wpf之家
出处:
http://www.cnblogs.com/wpf123
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
洛谷 P1236 算24点
洛谷 P1483 序列变换
洛谷 P2071 座位安排 seat.cpp/c/pas
洛谷 P3079 [USACO13MAR]农场的画Farm Painting
洛谷 P3912 素数个数
洛谷 P1617 爱与愁的一千个伤心的理由
洛谷 P1894 [USACO4.2]完美的牛栏The Perfect Stall
hdu_5908_Abelian Period(暴力)
hdu_4283_You Are the One(区间DP)
hdu_5903_Square Distance(dp)
原文地址:https://www.cnblogs.com/wpf123/p/2347372.html
最新文章
Ponds----hdu5438(拓扑排序)
Drainage Ditches---hdu1532(最大流, 模板)
Currency Exchange---poj1860 ( spfa, 回路,最长路)
Wormholes---poj3259(最短路 spfa 判断负环 模板)
Find them, Catch them---poj1703(并查集)
Bungee Jumping---hdu1155(物理题)
Can you solve this equation?---hdu2199(二分)
MediaInfo源代码分析 2:API函数
QoE的定义及影响因素
数字彩色电视摄像机结构
热门文章
3D视频的质量评价报告 (MSU出品)
3D视频可能出现的质量问题 (MSU出品)
主流H.264编码器对比测试 (MSU出品)
VC 2008 Express下安装OpenCV2.3.1
《嵌入式》复习资料公共版
Flex中的图表
Flex+BlazeDs+Java的教程及Demo
洛谷 P1518 两只塔姆沃斯牛 The Tamworth Two
洛谷 P3420 [POI2005]SKA-Piggy Banks
l洛谷 P2326 AKN’s PPAP
Copyright © 2011-2022 走看看