Пример #1
0
        public static DirectoryEntry CreateSite(SiteObj siteObj)
        {
            DirectoryEntry result;

            try
            {
                if (IISHelper.IsExistSite(siteObj.SiteName))
                {
                    IISHelper.DelSite(siteObj.SiteName);
                }
                DirectoryEntry directoryEntry  = new DirectoryEntry("IIS://localhost/w3svc");
                DirectoryEntry directoryEntry2 = directoryEntry.Children.Add(IISHelper.GetNewWebSiteID(), "IIsWebServer");
                directoryEntry2.Properties["ServerComment"].Value   = siteObj.SiteName;
                directoryEntry2.Properties["ServerBindings"].Value  = string.Format("{0}:{1}:{2}", "", siteObj.Port, "");
                directoryEntry2.Properties["ServerAutoStart"].Value = true;
                DirectoryEntry directoryEntry3 = directoryEntry2.Children.Add("Root", "IIsWebVirtualDir");
                directoryEntry3.Properties["Path"].Value              = siteObj.SitePath;
                directoryEntry3.Properties["AccessRead"][0]           = true;
                directoryEntry3.Properties["AccessExecute"][0]        = false;
                directoryEntry3.Properties["AccessWrite"][0]          = false;
                directoryEntry3.Properties["AccessScript"][0]         = true;
                directoryEntry3.Properties["EnableDirBrowsing"][0]    = false;
                directoryEntry3.Properties["DefaultDoc"][0]           = "UserLogin.aspx,Default.aspx";
                directoryEntry3.Properties["AppPoolId"][0]            = siteObj.SiteName;
                directoryEntry3.Properties["AspEnableParentPaths"][0] = true;
                if (IISHelper.GetIISMajorVersion() < 7)
                {
                    string text     = ".asp,[system32]\\asp.dll,5,GET,HEAD,POST,TRACE\r\n.cer,[system32]\\asp.dll,5,GET,HEAD,POST,TRACE\r\n.cdx,[system32]\\asp.dll,5,GET,HEAD,POST,TRACE\r\n.asa,[system32]\\asp.dll,5,GET,HEAD,POST,TRACE\r\n.idc,[system32]\\httpodbc.dll,5,GET,POST\r\n.shtm,[system32]\\ssinc.dll,5,GET,POST\r\n.shtml,[system32]\\ssinc.dll,5,GET,POST\r\n.stm,[system32]\\ssinc.dll,5,GET,POST\r\n.asax,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.ascx,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.ashx,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.asmx,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.aspx,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.axd,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.vsdisco,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.rem,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.soap,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.config,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.cs,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.csproj,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.vb,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.vbproj,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.webinfo,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.licx,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.resx,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.resources,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.xoml,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.rules,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.master,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.skin,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.compiled,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.browser,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.mdb,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.jsl,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.vjsproj,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.sitemap,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.msgx,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.ad,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.dd,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.ldd,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.sd,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.cd,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.adprototype,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.lddprototype,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.sdm,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.sdmDocument,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.ldb,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.svc,[netpath]\\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG\r\n.mdf,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.ldf,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.java,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.exclude,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG\r\n.refresh,[netpath]\\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG";
                    string newValue = Environment.SystemDirectory + "\\inetsrv";
                    string text2    = RuntimeEnvironment.GetRuntimeDirectory().TrimEnd(new char[]
                    {
                        '\\'
                    });
                    if (IISHelper.GetOSBit() == 64 && text2.IndexOf("Framework64") == -1)
                    {
                        text2 = text2.Replace("Framework", "Framework64");
                    }
                    text = text.Replace("[system32]", newValue).Replace("[netpath]", text2);
                    string[] value = Regex.Split(text, "\r\n");
                    directoryEntry3.Properties["ScriptMaps"].Value   = value;
                    directoryEntry3.Properties["AppFriendlyName"][0] = "默认应用程序";
                    directoryEntry3.Invoke("AppCreate", new object[]
                    {
                        true
                    });
                }
                directoryEntry3.CommitChanges();
                directoryEntry2.CommitChanges();
                result = directoryEntry3;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
Пример #2
0
        public static Dictionary <string, SiteObj> GetSiteNames()
        {
            Dictionary <string, SiteObj> dictionary = new Dictionary <string, SiteObj>();
            int iISMajorVersion = IISHelper.GetIISMajorVersion();

            if (iISMajorVersion == 6)
            {
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("root\\MicrosoftIISv2", "SELECT * FROM IIsWebServerSetting");
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        SiteObj          siteObj          = new SiteObj();
                        siteObj.SiteName        = managementObject["ServerComment"].ToString();
                        siteObj.SiteNameQuanPin = PinyinHelper.GetPinyin(siteObj.SiteName).ToUpper();
                        siteObj.SiteNameDuanPin = PinyinHelper.GetFirstPinyin(siteObj.SiteName).ToUpper();
                        siteObj.PoolName        = managementObject["AppPoolId"].ToString();
                        ManagementBaseObject[] array = (ManagementBaseObject[])managementObject["ServerBindings"];
                        siteObj.Port = array[0]["Port"].ToString();
                        int num = 0;
                        while (dictionary.ContainsKey(siteObj.SiteName))
                        {
                            num++;
                            siteObj.SiteName = managementObject["ServerComment"].ToString() + "_" + num.ToString();
                        }
                        dictionary.Add(siteObj.SiteName, siteObj);
                    }
                }
            }
            else
            {
                ServerManager serverManager = new ServerManager();
                foreach (Site current in serverManager.Sites)
                {
                    SiteObj siteObj = new SiteObj();
                    siteObj.SiteName        = current.Name;
                    siteObj.SiteNameQuanPin = PinyinHelper.GetPinyin(siteObj.SiteName).ToUpper();
                    siteObj.SiteNameDuanPin = PinyinHelper.GetFirstPinyin(siteObj.SiteName).ToUpper();
                    siteObj.PoolName        = ((current.Applications.Count > 0) ? current.Applications[0].ApplicationPoolName : "");
                    siteObj.Port            = current.Bindings[0].EndPoint.Port.ToString();
                    siteObj.SitePath        = ((current.Applications.Count > 0) ? current.Applications[0].VirtualDirectories[0].PhysicalPath : "");
                    int num = 0;
                    while (dictionary.ContainsKey(siteObj.SiteName))
                    {
                        num++;
                        siteObj.SiteName = current.Name + "_" + num.ToString();
                    }
                    dictionary.Add(siteObj.SiteName, siteObj);
                }
            }
            return(dictionary);
        }