Beispiel #1
0
        public IIsVirtualDirectoryInfo CreateNewSite(Site site, string webSiteId, out FaultContract Fault)
        {
            string status = string.Empty;

            Fault = null;
            if (!string.IsNullOrEmpty(site.IISPath) && !string.IsNullOrEmpty(site.IISHost))
            {
                string iisLocation = string.Empty;

                // Check if we can query IIS
                string pathToQuery = string.Format("IIS://{0}/W3SVC", site.IISHost);

                // Get the location of the the website running at this host and that port .. as Active Directory entry
                iisLocation = IISHelper.GetIISLocation(site.IISHost, string.Format(":{0}:", site.IISPort), out status);

                string websitePhysicalPath = GetPhysicalPathForSite(site, false, out Fault);
                if (!string.IsNullOrEmpty(status))
                {
                    Fault = new FaultContract
                    {
                        FaultType = "Error",
                        Message   = "Error retrieving physical path for site.Server:- " + site.IISHost + " Port:- " + site.IISPort + " Status:- " + status
                    };
                    return(null);
                }

                // When doing File I/O .. we need UNC paths .. but for IIS Helper .. we need a normal path
                string websiteUNCPath = GetPhysicalPathForSite(site, true, out Fault);
                if (!Directory.Exists(websiteUNCPath))
                {
                    Directory.CreateDirectory(websiteUNCPath);
                }
                if (IISHelper.VirtualDirectoryExists(iisLocation, site.IISPath, out status))
                {
                    Fault = new FaultContract
                    {
                        FaultType = "Error",
                        Message   = "Virtual Directory already exists" + status
                    };
                    return(null);
                }
                if (IISHelper.CreateVirtualDirectory(iisLocation + "/Root", site.IISPath, websitePhysicalPath, out status))
                {
                    IIsVirtualDirectoryInfo vDir = new IIsVirtualDirectoryInfo {
                        ADSIPath     = pathToQuery + "/" + site.IISPath,
                        Name         = site.Name,
                        PhysicalPath = websiteUNCPath,
                        VirtualPath  = site.IISPath
                    };
                    return(vDir);
                }
            }
            return(null);
        }
        public IIsVirtualDirectoryInfo CreateNewSite(Site site, string webSiteId, out FaultContract Fault)
        {
            string status = string.Empty;
            Fault = null;
            if (!string.IsNullOrEmpty(site.IISPath) && !string.IsNullOrEmpty(site.IISHost))
            {
                string iisLocation = string.Empty;

                // Check if we can query IIS
                string pathToQuery = string.Format("IIS://{0}/W3SVC", site.IISHost);                

                // Get the location of the the website running at this host and that port .. as Active Directory entry
                iisLocation = IISHelper.GetIISLocation(site.IISHost, string.Format(":{0}:", site.IISPort), out status);

                string websitePhysicalPath = GetPhysicalPathForSite(site, false, out Fault);
                if (!string.IsNullOrEmpty(status))
                {
                    Fault = new FaultContract
                    {
                        FaultType = "Error",
                        Message = "Error retrieving physical path for site.Server:- " + site.IISHost + " Port:- " + site.IISPort + " Status:- " + status
                    };
                    return null;
                }

                // When doing File I/O .. we need UNC paths .. but for IIS Helper .. we need a normal path
                string websiteUNCPath = GetPhysicalPathForSite(site, true, out Fault);
                if (!Directory.Exists(websiteUNCPath))
                {
                    Directory.CreateDirectory(websiteUNCPath);
                }
                if (IISHelper.VirtualDirectoryExists(iisLocation, site.IISPath, out status))
                {
                    Fault = new FaultContract
                    {
                        FaultType = "Error",
                        Message = "Virtual Directory already exists" + status
                    };
                    return null;
                }
                if (IISHelper.CreateVirtualDirectory(iisLocation + "/Root", site.IISPath, websitePhysicalPath, out status))
                {
                    IIsVirtualDirectoryInfo vDir = new IIsVirtualDirectoryInfo {
                        ADSIPath = pathToQuery + "/" + site.IISPath,
                         Name = site.Name,
                        PhysicalPath = websiteUNCPath,
                         VirtualPath = site.IISPath
                    };
                    return vDir;
                }
            }
            return null;
        }
Beispiel #3
0
        /// <summary>
        /// Recursive helper routine to look within IIsWebDirectories
        /// </summary>
        /// <param name="applicationDirs">List of application directory objects to append to.</param>
        /// <param name="objChildDE">The current Directory entry to look under.</param>
        /// <param name="webSiteMetabasePath">ADSI path for the website that houses the app-dir</param>
        /// <param name="webSitePhysicalDirectory">UNC path for the website that houses the app-dir</param>
        private static void GetNestedApplicationDirectoriesForWebDirectory(List <IIsVirtualDirectoryInfo> applicationDirs, DirectoryEntry objChildDE,
                                                                           string webSiteMetabasePath, string webSitePhysicalDirectory)
        {
            if (IsVirtualDirectoryAnApplication(objChildDE))
            {
                IIsVirtualDirectoryInfo virtualDir = new IIsVirtualDirectoryInfo();

                string adsiPath = objChildDE.Path;

                // IIS://Localhost/W3svc/1/Root/Dir3/nested
                virtualDir.ADSIPath = adsiPath;
                virtualDir.Name     = objChildDE.Name;

                // remove the website ADSI section to make it of the format /Dir3/nested
                string webAppVirtualPath = adsiPath.Replace(webSiteMetabasePath, string.Empty);
                virtualDir.VirtualPath = webAppVirtualPath;

                string webAppPath = (string)objChildDE.Properties["Path"].Value;
                if (!string.IsNullOrEmpty(webAppPath))
                {
                    virtualDir.PhysicalPath = webAppPath;
                }
                else                 // we couldn't get the path property
                {
                    // make it a physical path relative to IIS root
                    webAppPath = webAppVirtualPath.Replace("/", "\\");
                    virtualDir.PhysicalPath = string.Format("{0}{1}", webSitePhysicalDirectory, webAppPath);
                }

                applicationDirs.Add(virtualDir);
            }
            else if (0 == string.Compare(objChildDE.SchemaClassName, "IIsWebDirectory") ||
                     0 == string.Compare(objChildDE.SchemaClassName, "IIsWebVirtualDir"))
            {
                DirectoryEntries obDirEntList = objChildDE.Children;
                // Process each child entry and add the name of virtual directory
                foreach (DirectoryEntry objChild in obDirEntList)
                {
                    GetNestedApplicationDirectoriesForWebDirectory(applicationDirs, objChild, webSiteMetabasePath, webSitePhysicalDirectory);
                }
            }
        }
		/// <summary>
		/// Recursive helper routine to look within IIsWebDirectories
		/// </summary>
        /// <param name="applicationDirs">List of application directory objects to append to.</param>
		/// <param name="objChildDE">The current Directory entry to look under.</param>
		/// <param name="webSiteMetabasePath">ADSI path for the website that houses the app-dir</param>
		/// <param name="webSitePhysicalDirectory">UNC path for the website that houses the app-dir</param>
		private static void GetNestedApplicationDirectoriesForWebDirectory(List<IIsVirtualDirectoryInfo> applicationDirs, DirectoryEntry objChildDE,
									string webSiteMetabasePath, string webSitePhysicalDirectory)
		{
			if(IsVirtualDirectoryAnApplication(objChildDE))
			{
				IIsVirtualDirectoryInfo virtualDir = new IIsVirtualDirectoryInfo();

				string adsiPath = objChildDE.Path;

				// IIS://Localhost/W3svc/1/Root/Dir3/nested
				virtualDir.ADSIPath = adsiPath;
                virtualDir.Name = objChildDE.Name;

				// remove the website ADSI section to make it of the format /Dir3/nested
				string webAppVirtualPath = adsiPath.Replace(webSiteMetabasePath, string.Empty);
				virtualDir.VirtualPath = webAppVirtualPath;

				string webAppPath = (string)objChildDE.Properties["Path"].Value;
				if (!string.IsNullOrEmpty(webAppPath))
				{
					virtualDir.PhysicalPath = webAppPath;
				}
				else // we couldn't get the path property
				{
					// make it a physical path relative to IIS root
					webAppPath = webAppVirtualPath.Replace("/", "\\");
					virtualDir.PhysicalPath = string.Format("{0}{1}", webSitePhysicalDirectory, webAppPath);
				}

				applicationDirs.Add(virtualDir);
			}
			else if (0 == string.Compare(objChildDE.SchemaClassName, "IIsWebDirectory") ||
					 0 == string.Compare(objChildDE.SchemaClassName, "IIsWebVirtualDir"))
			{
				DirectoryEntries obDirEntList = objChildDE.Children;
				// Process each child entry and add the name of virtual directory
				foreach (DirectoryEntry objChild in obDirEntList)
				{
					GetNestedApplicationDirectoriesForWebDirectory(applicationDirs, objChild, webSiteMetabasePath, webSitePhysicalDirectory);
				}
			}
		}