private void CreateSite(string siteName, string ip, string port, string domain, string contentPath, string userName, string userPassword, string appPool)
		{
			SetProgressText("Creating web site...");

			Log.WriteStart("Creating web site");
			Log.WriteInfo(string.Format("Creating web site \"{0}\" ( IP: {1}, Port: {2}, Domain: {3} )", siteName, ip, port, domain));
			Version iisVersion = Wizard.SetupVariables.IISVersion;
			bool iis7 = (iisVersion.Major == 7);

			//check for existing site
			string oldSiteId = iis7 ? WebUtils.GetIIS7SiteIdByBinding(ip, port, domain) : WebUtils.GetSiteIdByBinding(ip, port, domain);
			if (oldSiteId != null)
			{
				// get site name
				string oldSiteName = iis7 ? oldSiteId : WebUtils.GetSite(oldSiteId).Name;
				throw new Exception(
					String.Format("'{0}' web site already has server binding ( IP: {1}, Port: {2}, Domain: {3} )",
					oldSiteName, ip, port, domain));
			}

			// create site
			WebSiteItem site = new WebSiteItem();
			site.Name = siteName;
			site.SiteIPAddress = ip;

			site.ContentPath = contentPath;
			//site.LogFileDirectory = logsPath;

			//set bindings
			ServerBinding binding = new ServerBinding(ip, port, domain);
			site.Bindings = new ServerBinding[] { binding };

			// set other properties
			site.AllowExecuteAccess = false;
			site.AllowScriptAccess = true;
			site.AllowSourceAccess = false;
			site.AllowReadAccess = true;
			site.AllowWriteAccess = false;
			site.AnonymousUsername = userName;
			site.AnonymousUserPassword = userPassword;
			site.AllowDirectoryBrowsingAccess = false;

			site.AuthAnonymous = true;
			site.AuthWindows = true;

			site.DefaultDocs = null; // inherit from service
			site.HttpRedirect = "";

			site.InstalledDotNetFramework = AspNetVersion.AspNet20;
			site.ApplicationPool = appPool;

			// create site
			string newSiteId = iis7 ? WebUtils.CreateIIS7Site(site) : WebUtils.CreateSite(site);
			
			//add rollback action
			if (iis7)
				RollBack.RegisterIIS7WebSiteAction(newSiteId);
			else
				RollBack.RegisterWebSiteAction(newSiteId);
			
			
			// update config setings
			string componentId = Wizard.SetupVariables.ComponentId;
			AppConfig.SetComponentSettingStringValue(componentId, "WebSiteId", newSiteId);
			AppConfig.SetComponentSettingStringValue(componentId, "WebSiteIP", ip);
			AppConfig.SetComponentSettingStringValue(componentId, "WebSitePort", port);
			AppConfig.SetComponentSettingStringValue(componentId, "WebSiteDomain", domain);
			AppConfig.SetComponentSettingStringValue(componentId, "VirtualDirectory", string.Empty);
			AppConfig.SetComponentSettingBooleanValue(componentId, "NewWebSite", true);
			AppConfig.SetComponentSettingBooleanValue(componentId, "NewVirtualDirectory", false);

			// update setup variables
			Wizard.SetupVariables.WebSiteId = newSiteId;

			//update log
			Log.WriteEnd("Created web site");
			
			//update install log
			InstallLog.AppendLine(string.Format("- Created a new web site named \"{0}\" ({1})", siteName, newSiteId));
			InstallLog.AppendLine("  You can access the application by the following URLs:");
			string[] urls = GetApplicationUrls(ip, domain, port, null);
			foreach (string url in urls)
			{
				InstallLog.AppendLine("  http://" + url);
			}
		}
		private void UpdateWebSiteBindings()
		{
			string component = Wizard.SetupVariables.ComponentFullName;
			string siteId = Wizard.SetupVariables.WebSiteId;
			string ip = Wizard.SetupVariables.WebSiteIP;
			string port = Wizard.SetupVariables.WebSitePort;
			string domain = Wizard.SetupVariables.WebSiteDomain;
			bool update = Wizard.SetupVariables.UpdateWebSite;
			Version iisVersion = Wizard.SetupVariables.IISVersion;
			bool iis7 = (iisVersion.Major == 7); 
			
			if (!update)
				return;
			
			//updating web site
			try
			{
				Log.WriteStart("Updating web site");
				Log.WriteInfo(string.Format("Updating web site \"{0}\" ( IP: {1}, Port: {2}, Domain: {3} )", siteId, ip, port, domain));

				//check for existing site
				string oldSiteId = iis7 ? WebUtils.GetIIS7SiteIdByBinding(ip, port, domain) : WebUtils.GetSiteIdByBinding(ip, port, domain);
				if (oldSiteId != null)
				{
					// get site name
					string oldSiteName = iis7 ? oldSiteId : WebUtils.GetSite(oldSiteId).Name;
					throw new Exception(
						String.Format("'{0}' web site already has server binding ( IP: {1}, Port: {2}, Domain: {3} )",
						oldSiteName, ip, port, domain));
				}

				ServerBinding newBinding = new ServerBinding(ip, port, domain);
				if ( iis7 )
					WebUtils.UpdateIIS7SiteBindings(siteId, new ServerBinding[] { newBinding });
				else
					WebUtils.UpdateSiteBindings(siteId, new ServerBinding[] { newBinding });


				// update config setings
				string componentId = Wizard.SetupVariables.ComponentId;
				AppConfig.SetComponentSettingStringValue(componentId, "WebSiteIP", ip);
				AppConfig.SetComponentSettingStringValue(componentId, "WebSitePort", port);
				AppConfig.SetComponentSettingStringValue(componentId, "WebSiteDomain", domain);

				//update log
				Log.WriteEnd("Updated web site");

				//update install log
				InstallLog.AppendLine("- Updated web site");
				InstallLog.AppendLine("  You can access the application by the following URLs:");
				string[] urls = GetApplicationUrls(ip, domain, port, null);
				foreach (string url in urls)
				{
					InstallLog.AppendLine("  http://" + url);
				}
			}
			catch (Exception ex)
			{
				if (Utils.IsThreadAbortException(ex))
					return;

				Log.WriteError("Update web site error", ex);
				throw;
			}

			//opening windows firewall ports
			try
			{
				OpenFirewallPort(component, port);
			}
			catch (Exception ex)
			{
				if (Utils.IsThreadAbortException(ex))
					return;

				Log.WriteError("Open windows firewall port error", ex);
			}
		}
Exemple #3
0
		/*internal static ServerBinding[] GetSiteBindings(string siteId)
		{
			// get web server settings object
			ManagementObject objSite = wmi.GetObject(String.Format("IIsWebServerSetting='{0}'", siteId));

			WebSiteItem site = new WebSiteItem();
			FillWebSiteFromWmiObject(site, objSite);
			return site.Bindings;
		}*/


		internal static void UpdateSiteBindings(string siteId, ServerBinding[] bindings)
		{
			ManagementObject objSite = wmi.GetObject(String.Format("IIsWebServerSetting='{0}'", siteId));

			// update bindings
			ManagementClass clsBinding = wmi.GetClass("ServerBinding");
			ManagementObject[] objBinings = new ManagementObject[bindings.Length];

			for (int i = 0; i < objBinings.Length; i++)
			{
				objBinings[i] = clsBinding.CreateInstance();
				objBinings[i]["Hostname"] = bindings[i].Host;
				objBinings[i]["IP"] = bindings[i].IP;
				objBinings[i]["Port"] = bindings[i].Port;
			}
			objSite.Properties["ServerBindings"].Value = objBinings;
			objSite.Put();
		}
Exemple #4
0
		internal static void UpdateIIS7SiteBindings(string siteId, ServerBinding[] bindings)
		{
			ServerManager serverManager = new ServerManager();
			Site webSite = serverManager.Sites[siteId];
			

			// cleanup all bindings
			webSite.Bindings.Clear();
			//
			foreach (ServerBinding binding in bindings)
			{
				//
				webSite.Bindings.Add(binding.IP + ":" + binding.Port + ":" + binding.Host,
					Uri.UriSchemeHttp);
			}
			//
			serverManager.CommitChanges();
		}
Exemple #5
0
        private void UpdateWebSiteBindings()
        {
            string component = Context.ComponentFullName;
            string siteId = Context.WebSiteId;
            string ip = Context.WebSiteIP;
            string port = Context.WebSitePort;
            string domain = Context.WebSiteDomain;
            bool update = Context.UpdateWebSite;
            Version iisVersion = Context.IISVersion;
            bool iis7 = (iisVersion.Major >= 7);

            if (!update)
                return;

            //updating web site
            try
            {
                Log.WriteStart("Updating web site");
                Log.WriteInfo(string.Format("Updating web site \"{0}\" ( IP: {1}, Port: {2}, Domain: {3} )", siteId, ip, port, domain));

                //check for existing site
                var oldSiteId = iis7 ? WebUtils.GetIIS7SiteIdByBinding(ip, port, domain) : WebUtils.GetSiteIdByBinding(ip, port, domain);
                // We found out that other web site has this combination of {IP:Port:Host Header} already assigned
                if (oldSiteId != null && !oldSiteId.Equals(Context.WebSiteId))
                {
                    // get site name
                    string oldSiteName = iis7 ? oldSiteId : WebUtils.GetSite(oldSiteId).Name;
                    throw new Exception(
                        String.Format("'{0}' web site already has server binding ( IP: {1}, Port: {2}, Domain: {3} )",
                        oldSiteName, ip, port, domain));
                }

                // Assign the binding only if is not defined
                if (String.IsNullOrEmpty(oldSiteId))
                {
                    ServerBinding newBinding = new ServerBinding(ip, port, domain);
                    if (iis7)
                        WebUtils.UpdateIIS7SiteBindings(siteId, new ServerBinding[] { newBinding });
                    else
                        WebUtils.UpdateSiteBindings(siteId, new ServerBinding[] { newBinding });
                }

                // update config setings
                string componentId = Context.ComponentId;
                AppConfig.SetComponentSettingStringValue(componentId, "WebSiteIP", ip);
                AppConfig.SetComponentSettingStringValue(componentId, "WebSitePort", port);
                AppConfig.SetComponentSettingStringValue(componentId, "WebSiteDomain", domain);

                //update log
                Log.WriteEnd("Updated web site");

                //update install log
                InstallLog.AppendLine("- Updated web site");
                InstallLog.AppendLine("  You can access the application by the following URLs:");
                string[] urls = GetApplicationUrls(ip, domain, port, null);
                //
                foreach (string url in urls)
                {
                    InstallLog.AppendLine("  http://" + url);
                }
            }
            catch (Exception ex)
            {
                if (Utils.IsThreadAbortException(ex))
                    return;

                Log.WriteError("Update web site error", ex);
                throw;
            }

            //opening windows firewall ports
            try
            {
                Utils.OpenFirewallPort(component, port, Context.IISVersion);
            }
            catch (Exception ex)
            {
                if (Utils.IsThreadAbortException(ex))
                    return;

                Log.WriteError("Open windows firewall port error", ex);
            }
        }