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();
}
查看全文
相关阅读:
进入全屏 nodejs+express+mysql实现restful风格的增删改查示例
WebAPI 实现前后端分离
android 集成支付宝app支付(原生态)-包括android前端与java后台
Windows 64 位系统下 Python 环境的搭建
Es6主要特征详解
js上传图片
Python socket
设置windows开机自启某个软件
oracle导入导出数据
mysql触发器,答题记录表同步教学跟踪(用户列表)
原文地址:https://www.cnblogs.com/ghd258/p/330899.html
最新文章
初步理解Python进程的信号通讯
经验之谈:如何为你的机器学习问题选择合适的算法?
Ubuntu 14.04快速搭建SVN服务器及日常使用
怎样不用鼠标,完全只靠键盘操作电脑?
python扩展实现方法--python与c混和编程
python下使用epoll
Python爬虫技巧
lombok使用基础教程
spring boot容器启动详解
Redis Cluster集群搭建与应用
热门文章
聚集索引与非聚集索引
Spring框架自学之路——简易入门
koa2教程(一)-快速开始
vue中的checkbox全选和反选
PHP日期时间处理
用Token令牌维护微服务之间的通信安全的实现
Pycharm及python安装详细教程
安装Maven并搭建Maven私有仓库
npm 与 package.json 快速入门
Spring Boot上传文件
Copyright © 2011-2022 走看看