Esempio n. 1
0
        private void btn_createweb_Click(object sender, EventArgs e)
        {
            Apps apps = QuickConfig.Common.setXml.getConfig(ConfigName).Apps;

            setIIS iis = new setIIS();

            foreach (webSiteCheck wsc in websitecheckList)
            {
                if (wsc.Check)
                {
                    WebApp webapp = apps.WebAppList.Find((WebApp wa) => wa.Name == wsc.Name);
                    iis.DelSite(webapp.SiteName);
                    NewWebSiteInfo info_framework = new NewWebSiteInfo(webapp.Ip, webapp.Port, "", webapp.SiteName, webapp.Path);
                    iis.CreateNewWebSite(info_framework, webapp.SiteName);
                    //创建网站的 虚拟目录
                    if (webapp.VirtualDirList != null && webapp.VirtualDirList.Count > 0)
                    {
                        foreach (WebAppVirtualDir virtualdir in webapp.VirtualDirList)
                        {
                            iis.CreateVirtualDirectory(webapp.SiteName, @"/", virtualdir.VirtualName, virtualdir.Path);
                        }
                    }
                }
            }

            setMessage.MessageShow("", "网站创建完成!", this.btn_createweb);
        }
Esempio n. 2
0
        private void InstallWebApps(InstallProgress.SetShow setShow)
        {
            this.Invoke(setShow, new object[] { "创建网站", 90 });
            writeLog("创建网站");
            int numStart = 90;
            int numMax   = 99;

            Common.setIIS iis = new Common.setIIS();
            foreach (WebApp webapp in set.Apps.WebAppList)
            {
                iis.DelSite(webapp.SiteName);
                NewWebSiteInfo info_framework = new NewWebSiteInfo(webapp.Ip, webapp.Port, "", webapp.SiteName, webapp.Path);
                iis.CreateNewWebSite(info_framework, webapp.SiteName);
                writeLog(webapp.Label + "创建完成");
            }
            if (numStart != numMax)
            {
                this.Invoke(setShow, new object[] { "网站创建完成", numStart });
                numStart++;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 创建网站
        /// </summary>
        /// <param name="siteInfo"></param>
        public DirectoryEntry CreateNewWebSite(NewWebSiteInfo siteInfo)
        {
            DirectoryEntry newSiteEntry = GetDirEntry(siteInfo.CommentOfWebSite, siteInfo.BindString);

            if (newSiteEntry != null)
            {
                //throw new Exception("该网站名或者端口已存在" + Environment.NewLine + siteInfo.BindString);
                return(newSiteEntry);
            }
            DirectoryEntry rootEntry = GetDirectoryEntry(entPath);

            var newSiteNum = GetNewWebSiteID();

            newSiteEntry = rootEntry.Children.Add(newSiteNum, "IIsWebServer");
            newSiteEntry.CommitChanges();

            newSiteEntry.Properties["ServerBindings"].Value = siteInfo.BindString;
            newSiteEntry.Properties["ServerComment"].Value  = siteInfo.CommentOfWebSite;
            newSiteEntry.CommitChanges();
            DirectoryEntry vdEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");

            vdEntry.CommitChanges();
            string ChangWebPath = siteInfo.WebPath.TrimEnd('\\');

            if (!Directory.Exists(ChangWebPath))
            {
                Directory.CreateDirectory(ChangWebPath);//创建目录
            }
            vdEntry.Properties["Path"].Value = ChangWebPath;


            vdEntry.Invoke("AppCreate", true);                                    //创建应用程序

            vdEntry.Properties["AccessRead"][0]      = true;                      //设置读取权限
            vdEntry.Properties["AccessWrite"][0]     = true;
            vdEntry.Properties["AccessScript"][0]    = true;                      //执行权限
            vdEntry.Properties["AccessExecute"][0]   = false;
            vdEntry.Properties["DefaultDoc"][0]      = "Default.aspx";            //设置默认文档
            vdEntry.Properties["AppFriendlyName"][0] = siteInfo.CommentOfWebSite; //应用程序名称
            vdEntry.Properties["AuthFlags"][0]       = 1;                         //0表示不允许匿名访问,1表示就可以3为基本身份验证,7为windows继承身份验证
            vdEntry.CommitChanges();

            //操作增加MIME
            //.dwf drawing/x-dwf
            //.dwg application/autocad
            //.dxf application/dxf
            //X-Powered-By ASP.NET
            var mineDic = siteInfo.MineDic;

            foreach (var str in mineDic)
            {
                IISOle.MimeMapClass NewMime = new IISOle.MimeMapClass();
                NewMime.Extension = str.Key; NewMime.MimeType = str.Value;
                vdEntry.Properties["MimeMap"].Add(NewMime);
            }
            if (mineDic.Count() > 0)
            {
                vdEntry.CommitChanges();
                rootEntry.CommitChanges();
            }

            #region 针对IIS7
            DirectoryEntry getEntity = new DirectoryEntry("IIS://localhost/W3SVC/INFO");
            int            Version   = int.Parse(getEntity.Properties["MajorIISVersionNumber"].Value.ToString());
            if (Version > 6)
            {
                #region 创建应用程序池
                string AppPoolName = siteInfo.CommentOfWebSite;
                if (!IsAppPoolName(AppPoolName))
                {
                    DirectoryEntry newpool;
                    DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                    newpool = appPools.Children.Add(AppPoolName, "IIsApplicationPool");

                    newpool.CommitChanges();
                }
                #endregion

                #region 修改应用程序的配置(包含托管模式及其NET运行版本)
                ServerManager sm = new ServerManager();
                sm.ApplicationPools[AppPoolName].ManagedRuntimeVersion = "v4.0";
                sm.ApplicationPools[AppPoolName].ManagedPipelineMode   = ManagedPipelineMode.Integrated; //托管模式Integrated为集成 Classic为经典
                sm.CommitChanges();
                #endregion

                vdEntry.Properties["AppPoolId"].Value = AppPoolName;
                vdEntry.CommitChanges();
            }
            #endregion


            //启动aspnet_regiis.exe程序
            string           fileName  = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe";
            ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
            //处理目录路径
            string path  = vdEntry.Path.ToUpper();
            int    index = path.IndexOf("W3SVC");
            path = path.Remove(0, index);
            //启动ASPnet_iis.exe程序,刷新脚本映射
            startInfo.Arguments              = "-s " + path;
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            Process process = new Process();
            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();
            string errors = process.StandardError.ReadToEnd();
            if (errors != string.Empty)
            {
                throw new Exception(errors);
            }
            return(newSiteEntry);
        }
Esempio n. 4
0
        /// <summary>
            /// 创建网站
            /// </summary>
            /// <param name="siteInfo"></param>
        public void CreateNewWebSite(string newSiteNum, NewWebSiteInfo siteInfo)
        {
            DirectoryEntry rootEntry    = GetDirectoryEntry(entPath);
            DirectoryEntry newSiteEntry = rootEntry.Children.Add(newSiteNum, "IIsWebServer");

            newSiteEntry.CommitChanges();
            newSiteEntry.Properties["ServerBindings"].Value = siteInfo.BindString;
            newSiteEntry.Properties["ServerComment"].Value  = siteInfo.CommentOfWebSite;
            newSiteEntry.CommitChanges();
            DirectoryEntry vdEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");

            vdEntry.CommitChanges();
            string ChangWebPath = siteInfo.WebPath.Trim().Remove(siteInfo.WebPath.Trim().LastIndexOf('\\'), 1);

            vdEntry.Properties["Path"].Value = ChangWebPath;

            vdEntry.Invoke("AppCreate", true);                       //创建应用程序
                        vdEntry.Properties["AccessRead"][0]  = true; //设置读取权限
                        vdEntry.Properties["AccessWrite"][0] = true;

            vdEntry.Properties["AccessScript"][0] = true;//执行权限
                        vdEntry.Properties["AccessExecute"][0] = false;

            vdEntry.Properties["DefaultDoc"][0] = "Login.aspx";                //设置默认文档
                        vdEntry.Properties["AppFriendlyName"][0] = newSiteNum; // "LabManager"; //应用程序名称          
                        vdEntry.Properties["AuthFlags"][0]       = 1;          // 0表示不允许匿名访问,1表示就可以3为基本身份验证,7为windows继承身份验证
                        vdEntry.CommitChanges();

                        //操作增加MIME
                        //IISOle.MimeMapClass NewMime = new IISOle.MimeMapClass();
                        //NewMime.Extension = ".xaml"; NewMime.MimeType = "application/xaml+xml";
                        //IISOle.MimeMapClass TwoMime = new IISOle.MimeMapClass();
                        //TwoMime.Extension = ".xap"; TwoMime.MimeType = "application/x-silverlight-app";
                        //rootEntry.Properties["MimeMap"].Add(NewMime);
                        //rootEntry.Properties["MimeMap"].Add(TwoMime);
                        //rootEntry.CommitChanges();
                            #region 针对IIS7
                        DirectoryEntry getEntity = new DirectoryEntry("IIS://localhost/W3SVC/INFO");
            int Version = int.Parse(getEntity.Properties["MajorIISVersionNumber"].Value.ToString());

            this.ShowMsg("得到IIS版本 " + Version);
            if (Version > 6)
            {
                                #region 创建应用程序池
                                string AppPoolName = newSiteNum;// "LabManager";
                if (!IsAppPoolName(AppPoolName))
                {
                    DirectoryEntry newpool;
                    DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                    newpool = appPools.Children.Add(AppPoolName, "IIsApplicationPool");
                    newpool.CommitChanges();
                    this.ShowMsg("创建应用程序池");
                }
                                #endregion

                                #region 修改应用程序的配置(包含托管模式及其NET运行版本)
                                ServerManager sm = new ServerManager();

                sm.ApplicationPools[AppPoolName].ManagedRuntimeVersion = "v4.0";
                sm.ApplicationPools[AppPoolName].ManagedPipelineMode   = ManagedPipelineMode.Classic; //托管模式Integrated为集成 Classic为经典
                                sm.CommitChanges();

                this.ShowMsg("修改站点配置 v4.0 和经典模式");
                                #endregion

                                vdEntry.Properties["AppPoolId"].Value = AppPoolName;
                vdEntry.CommitChanges();
            }
                        #endregion

                        //启动aspnet_regiis.exe程序
                        //string fileName = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe";
                        //ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
                        ////处理目录路径
                        //string path = vdEntry.Path.ToUpper();
                        //int index = path.IndexOf("W3SVC");
                        //path = path.Remove(0, index);
                        ////启动ASPnet_iis.exe程序,刷新脚本映射
                        //startInfo.Arguments = "-s " + path;
                        //startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        //startInfo.UseShellExecute = false;
                        //startInfo.CreateNoWindow = true;
                        //startInfo.RedirectStandardOutput = true;
                        //startInfo.RedirectStandardError = true;
                        //Process process = new Process();
                        //process.StartInfo = startInfo;
                        //process.Start();
                        //process.WaitForExit();
                        //string errors = process.StandardError.ReadToEnd();
                        //if (errors != string.Empty)
                        //{
                        //    throw new Exception(errors);
                        //}
        }