惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 随风

释放C盘空间的27招优化技巧 数据库索引应用(ms-sql) 使用命令行导入导出方案(oracle) 使用C#调用DTS包 网页效果集合(小技巧) - 随风 - 博客园 ORACLE常用傻瓜問題1000問 网络命令一览表 自定义应用程序配置文件(app.config) XmlHttp异步获取网站数据 - 随风 - 博客园 页面无刷新获取数据的几种方式浅析 利用XMLHTTP无刷新添加数据 利用XMLHTTP无刷新自动实时更新数据 数据完整性管理 推模式中的水晶报表参数赋值 C#图像处理 有关打印、收藏等的JS代码(打印等主要使用了一个IE组件来实现) C#操作注册表 SOS!! 求助 如何在asp.net中保存用户状态
对虚拟目录的操作
随风 · 2005-02-24 · via 博客园 - 随风

之前做站点发布的时候,有用到对虚拟目录的操作,今天抽时间整理了一下,大概如下:
一、查看虚拟目录是否存在
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();
}