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
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
使用truffle测试部署合约
nodejs promise深度解析
pthread线程特定数据
基于信号量与互斥锁实现的生产者和消费者
Linux coredump 的打开和关闭
Linux 双网卡配置两个IP同时只有一个会通的原因
进程间通信-共享内存
进程间通信-消息队列
TCP/IP SIGPIPE信号
Select模式和超时
原文地址:https://www.cnblogs.com/wpf123/p/2347372.html
最新文章
浅淡Webservice、WSDL三种服务访问的方式(附案例)
WebService学习笔记
one way WebService
eclipse+PyDev 中报错"scrapy.spiders.Spider" ,可用"# @UndefinedVariable"压制.
scrapy shell 中文网站输出报错.记录.
easyui-helloworld
例子: 自制Flask首页导航.
datagrid合并行列--并不能影响序号列内容...(formatter的锅.)
一个失败的首页导航例子
Flask,HelloWorld
热门文章
python编码问题.
python+sqlite3
Python GUI with Tkinter (from youtube) 在youtube上能找到很多编程视频...
c++学习
eos教程如何创建eos测试账号并且使用scatter插件
vscode开发智能合约
为什么安装beego和框架的失败 以及常用命令
cenos环境变量配置
三大框架整合
java poi技术读取到数据库
Copyright © 2011-2022 走看看