zoukankan      html  css  js  c++  java
  • 使用ASP.NET创建IIS站点或虚拟目录(下)

    ///<summary>
            /// Delete the virtual directory in the WebServer
            ///</summary>
            ///<param name="website">webserver name</param>
            ///<param name="vdir">virtual directory name</param>
            public static void DeleteVirtualDir(string website, string vdir)
            {
                if (!GetVirtualDir(website, vdir)) throw new Exception(" The virtual directory don't exist in the website");
                using (DirectoryEntry de = GetWebSiteInfo(website))
                {
                    foreach (DirectoryEntry sub in de.Children)
                    {
                        if (sub.Name == vdir)
                        {
                            de.Invoke("Delete", new string[] { sub.SchemaClassName, vdir });
                            de.CommitChanges();
                        }
                    }
                }
            }
     
     
            private static void UpdateVDirInfo(DirectoryEntry newDE, ref System.Data.PropertyCollection properties)
            {
                //newDE.Properties["AnonyMousUserName"][0] = properties["AnonymousUserName"].ToString();
                //newDE.Properties["AnonymousUserPass"][0] = properties["AnonymousUserPass"].ToString();
                newDE.Properties["AccessRead"][0] = (bool)properties["AccessRead"];
                newDE.Properties["AccessExecute"][0] = (bool)properties["AccessExecute"];
                newDE.Properties["AuthBasic"][0] = (bool)properties["AuthBasic"];
                newDE.Properties["AuthNTLM"][0] = (bool)properties["AuthNTLM"];
                newDE.Properties["ContentIndexed"][0] = (bool)properties["ContentIndexed"];
                newDE.Properties["EnableDefaultDoc"][0] = (bool)properties["EnableDefaultDoc"];
                newDE.Properties["EnableDirBrowsing"][0] = (bool)properties["EnableDirBrowsing"];
                newDE.Properties["AccessSSL"][0] = (bool)properties["AccessSSL"];
                newDE.Properties["AccessScript"][0] = (bool)properties["AccessScript"];
                newDE.Properties["DefaultDoc"][0] = properties["DefaultDoc"].ToString();
                newDE.Properties["Path"][0] = properties["Path"].ToString();
                newDE.Properties["AppIsolated"][0] = (int)properties["AppIsolated"];
                newDE.Properties["AppFriendlyName"][0] = properties["AppFriendlyName"].ToString();
                newDE.Properties["AccessFlags"][0] = (int)properties["AccessFlags"];
                newDE.Properties["FrontPageWeb"][0] = (int)properties["FrontPageWeb"];
                //newDE.Properties["DontLog"][0] = (bool)properties["DontLog"];
                //newDE.Properties["AppRoot"][0] = properties["AppRoot"].ToString();
            }
     
     
     
            private static bool GetVirtualDir(string webSite, string dirName)
            {
                bool result = false;
                using (DirectoryEntry de = GetWebSiteInfo(webSite))
                {
                   
                    if (de != null)
                    {
                        foreach (DirectoryEntry subVD in de.Children)
                        {
                            if (subVD.SchemaClassName == "IIsWebVirtualDir" && subVD.Name == dirName)
                            {
                                result = true;
                                break;
                            }
                        }
                    }
                }
                return result;
               
            }
     
            private static void GetWebSiteInfo(ref Hashtable webServer)
            {
                DirectoryEntries des = iisDE.Children;
                foreach (DirectoryEntry subDE in des)
                {
                   if (subDE.SchemaClassName == "IIsWebServer")
                   {
                      webServer.Add(subDE.Properties["ServerComment"].Value.ToString(), subDE.Name);
                   }
                }
                des = null;
          
            }
     
            private static DirectoryEntry GetWebSiteInfo(string website)
            {
                DirectoryEntry result = null;
                DirectoryEntries des = iisDE.Children;
                foreach (DirectoryEntry subDE in des)
                {
                    if (subDE.SchemaClassName == "IIsWebServer" && subDE.Properties["ServerComment"].Value.ToString() == website)
                    {
                        result = subDE.Children.Find("Root", "IIsWebVirtualDir");
                        break;
                    }
     
                }
                des = null;
                return result;
     
            }
     
            private static int GetWebSiteInfo(int port)
            {
                int result = 1,i=1;
                DirectoryEntries des = iisDE.Children;
                foreach (DirectoryEntry subDE in des)
                {
                    if (subDE.SchemaClassName == "IIsWebServer")
                    {
                        if ((i = Convert.ToInt32(subDE.Name)) >= result)
                        {
                            result = i + 1;
                        }
                        if (subDE.Properties["ServerBindings"][0].ToString() == ":" + port.ToString() + ":")
                        {
                            throw new Exception(" The port is already used");
                        }
                    }
               }
               des = null;
               return result;
            }
     
                   
    }
     
     
    注意在很多文章中认为vde.Invoke("AppCreate", true);可有可无,但该方法能激活网站应用,相当于在一个虚拟目录中的Application settings中点击Create按钮来创建该目录的应用
  • 相关阅读:
    FFmpeg命令:几种常见场景下的FFmpeg命令(摄像头采集推流,桌面屏幕录制推流、转流,拉流等等)
    javaCV入门指南:序章
    javacpp-FFmpeg系列补充:FFmpeg拉流截图实现在线演示demo(视频截图并返回base64图像,支持jpg/png/gif/bmp等多种格式)
    javacpp-FFmpeg系列之3: 像素图像数据转换(BGR与BufferdImage互转,RGB与BufferdImage互转,BufferdImage转Base64编码)
    javacpp-FFmpeg系列补充:FFmpeg解决avformat_find_stream_info检索时间过长问题
    javacpp-FFmpeg系列之2:通用拉流解码器,支持视频拉流解码并转换为YUV、BGR24或RGB24等图像像素数据
    Cache系列:spring-cache简单三步快速应用ehcache3.x-jcache缓存(spring4.x)
    运维程序】简单的命令控制器(支持定时命令执行、重复定时任务命令和进程管理,开发这个小程序主要是为了方便管理服务进程)【个人github项目】
    javacpp-FFmpeg系列之1:视频拉流解码成YUVJ420P,并保存为jpg图片
    spring-data详解之spring-data-jpa:简单三步快速上手spring-data-jpa开发
  • 原文地址:https://www.cnblogs.com/scgw/p/1944606.html
Copyright © 2011-2022 走看看