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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - stonespawn

Vue 组件库2 Vue 的组件库 算法小题目 VS2019 自动代码补全功能 GIT 删除操作 vue-router 注意事项 Vue中axios访问 后端跨域问题 Vue2.0 搭配 axios Vue 脚手架搭建 grunt使用入门 Git相关操作及记录 Ajax在调用含有SoapHeader的webservice方法 关于JS 树形结构 导出EXCEL【Web方式HTML通过拼接html中table】 链接点击跳动问题 WatiN——Web自动化测试(三)【弹出窗口处理】 WatiN——Web自动化测试(二) WatiN——Web自动化测试(一) 网页调用服务程序 - stonespawn - 博客园
小问题 小技巧 :创建虚拟目录并将IIS里面.net配置版本设为2.0 - stonespawn
stonespawn · 2009-02-24 · via 博客园 - stonespawn
  

        工作闲时:做一个小功能,就是用C#语法创建一个虚拟目录,从网上搜搜都是,但是呢如果机器的.net framework的版本很多,需要设置框架的版本改如何写呢?

       public static string VirDirSchemaName = "IIsWebVirtualDir";
      

        public string CreateVirtualDirectory(string nameDirectory, string realPath, string defaultPage)

        {

            string _serverName = "localhost";

            DirectoryEntry _iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");

            DirectoryEntry folderRoot = _iisServer.Children.Find("ROOT", VirDirSchemaName);

            if (folderRoot == null)

                return "IIS 未正常安装";

            if (folderRoot.Children == null)

                return "IIS 可能未启动";

            DirectoryEntry existPath = null;

            try

            {

                existPath = folderRoot.Children.Find(nameDirectory, VirDirSchemaName);

            }

            catch (Exception e)

            {}

            if (existPath != null)

            {

                StringBuilder sb;

                sb = new StringBuilder();

                System.DirectoryServices.PropertyCollection props = existPath.Properties;

                foreach (System.DirectoryServices.PropertyValueCollection valcol in existPath.Properties)

                {

                    sb.Append(valcol.PropertyName);

                    sb.Append ( ":" );

                    sb.Append ( valcol.Value.ToString());

                    sb.Append ("\r");

                }

                string f = sb.ToString();

            }

            DirectoryEntry newVirDir = null;

            try

            {

                newVirDir = folderRoot.Children.Add(nameDirectory, folderRoot.SchemaClassName);

            }

            catch (Exception e)

            {

                return "Sorry!Error when adding the virtual path. Return message is : " + e.Message;

            }

            try

            {

                newVirDir.Properties["Path"].Insert(0, realPath);       // 虚拟目录的绝对路径

                newVirDir.Properties["AuthFlags"][0] = 5; //1:anonymouse, 4:windows

                newVirDir.Properties["AccessExecute"][0] = false;       // 可执行文件。执行权限下拉菜单中

                newVirDir.Properties["AccessRead"][0] = true;           // 读取

                newVirDir.Properties["AccessWrite"][0] = false;          // 写入

                newVirDir.Properties["AccessScript"][0] = true;         // 可执行脚本。执行权限下拉菜单中

                newVirDir.Properties["ContentIndexed"][0] = true;       // 资源索引

                newVirDir.Properties["DefaultDoc"][0] = defaultPage; // DefaultPage;    // 默认页面

                newVirDir.Properties["AppFriendlyName"][0] = "友好的目录名称";   // 友好的显示名称

                newVirDir.Properties["AppIsolated"][0] = 2;             // 0 表示应用程序在进程内运行,值1 表示进程外,值2 表示进程池

                newVirDir.Properties["DontLog"][0] = true;

                newVirDir.Properties["ScriptMaps"].Value = ScriptArray().ToArray();

                newVirDir.Invoke("AppCreate", true); //q确保创建成功

                newVirDir.CommitChanges();

                folderRoot.CommitChanges();

                _iisServer.CommitChanges();

                return "Add success";

            }

            catch (Exception e)

            {

                return "Error  message is : " + e.Message;

}

           return "-----------";

}

public ArrayList ScriptArray()
     {    
         ArrayList list = new ArrayList();
        string[] array={".ascx",".asmx",".aspx",".config"};
        for (int i = 0; i < array.Length; i++)
               {
                        list.Add(array[i] + @",c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
               }
         return list;
   }

            将Asp.net框架的版本设为2.0,其实在虚拟目录属性添加一个属性即可,newVirDir.Properties["ScriptMaps"].Value = ScriptArray().ToArray();

           newVirDir.Properties["ScriptMaps"].Value  是将获得一个object的数组。

          做的时候,跟本不知道虚拟目录到底有哪些属性,可是项目经理提示一下,就犹醍醐灌顶,他说创建一个目录,然后读取。有时候解决问题原来可以这样。

        希望给大家带来点收获。