使用ServerManager列出按类型

时间:2016-12-06 19:08:54

标签: c# iis c#-4.0 configuration iis-7

我使用ServerManager(Microsoft.Web.Administration.dll)创建应用程序来管理我的Web服务器,我的所有服务器都运行IIS 7及更高版本。该网站的大部分内容已经完成,我可以管理服务器,网站,FTP,SSL等。

这是我的问题, 我能够创建虚拟目录和应用程序,但在查看站点信息时遇到问题,就像在IIS中一样。我只能通过获取item.VirtualDirectories[0].PhysicalPath将所有内容列为虚拟目录,但希望在一列中显示应用程序,在第二列中显示基本虚拟目录。我确定我需要寻找根应用程序路径是否为siteid,或者它是否有某种方式的AppPool,但很难确定如何。任何帮助,将不胜感激。 我的代码:

SiteVirtualDirectory.cs

private string anonymousUsername;
    private string anonymousUserPassword;
    private string contentPath;
    private bool enableWritePermissions;
    private bool enableParentPaths;
    private bool enableDirectoryBrowsing;
    private bool enableAnonymousAccess;
    private bool enableWindowsAuthentication;
    private bool enableBasicAuthentication;
    private bool enableDynamicCompression;
    private bool enableStaticCompression;
    private string defaultDocs;
    private string httpRedirect;
    private HttpError[] httpErrors;
    private HttpErrorsMode errorMode;
    private HttpErrorsExistingResponse existingResponse;
    private MimeMap[] mimeMaps; 
    private HttpHeader[] httpHeaders;
    private bool aspInstalled;
    private string aspNetInstalled;
    private string phpInstalled;
    private bool perlInstalled;
    private bool pythonInstalled;
    private bool coldfusionInstalled;
    private bool cgiBinInstalled;
    private string applicationPool;
    private bool dedicatedApplicationPool;
    private string parentSiteName;
    private bool redirectExactUrl;
    private bool redirectDirectoryBelow;
    private bool redirectPermanent;
    private bool sharePointInstalled;
    private bool iis7;
    private string consoleUrl;
    private string php5VersionsInstalled;

    public string AnonymousUsername
    {
        get { return anonymousUsername; }
        set { anonymousUsername = value; }
    }

    public string AnonymousUserPassword
    {
        get { return anonymousUserPassword; }
        set { anonymousUserPassword = value; }
    }

    public string ContentPath
    {
        get { return contentPath; }
        set { contentPath = value; }
    }

    public string HttpRedirect
    {
        get { return httpRedirect; }
        set { httpRedirect = value; }
    }

    public string DefaultDocs
    {
        get { return defaultDocs; }
        set { defaultDocs = value; }
    }

    public MimeMap[] MimeMaps
    {
        get { return mimeMaps; }
        set { mimeMaps = value; }
    }

    public HttpError[] HttpErrors
    {
        get { return httpErrors; }
        set { httpErrors = value; }
    }

    public HttpErrorsMode ErrorMode
    {
        get { return errorMode; }
        set { errorMode = value; }
    }

    public HttpErrorsExistingResponse ExistingResponse
    {
        get { return existingResponse; }
        set { existingResponse = value; }
    }

    public string ApplicationPool
    {
        get { return this.applicationPool; }
        set { this.applicationPool = value; }
    }

    public bool EnableParentPaths
    {
        get { return this.enableParentPaths; }
        set { this.enableParentPaths = value; }
    }

    public HttpHeader[] HttpHeaders
    {
        get { return this.httpHeaders; }
        set { this.httpHeaders = value; }
    }

    public bool EnableWritePermissions
    {
        get { return this.enableWritePermissions; }
        set { this.enableWritePermissions = value; }
    }

    public bool EnableDirectoryBrowsing
    {
        get { return this.enableDirectoryBrowsing; }
        set { this.enableDirectoryBrowsing = value; }
    }

    public bool EnableAnonymousAccess
    {
        get { return this.enableAnonymousAccess; }
        set { this.enableAnonymousAccess = value; }
    }

    public bool EnableWindowsAuthentication
    {
        get { return this.enableWindowsAuthentication; }
        set { this.enableWindowsAuthentication = value; }
    }

    public bool EnableBasicAuthentication
    {
        get { return this.enableBasicAuthentication; }
        set { this.enableBasicAuthentication = value; }
    }

    public bool EnableDynamicCompression
    {
        get { return this.enableDynamicCompression; }
        set { this.enableDynamicCompression = value; }
    }
    public bool EnableStaticCompression
    {
        get { return this.enableStaticCompression; }
        set { this.enableStaticCompression = value; }
    }

    public bool AspInstalled
    {
        get { return this.aspInstalled; }
        set { this.aspInstalled = value; }
    }

    public string AspNetInstalled
    {
        get { return this.aspNetInstalled; }
        set { this.aspNetInstalled = value; }
    }

    public string PhpInstalled
    {
        get { return this.phpInstalled; }
        set { this.phpInstalled = value; }
    }

    public bool PerlInstalled
    {
        get { return this.perlInstalled; }
        set { this.perlInstalled = value; }
    }

    public bool PythonInstalled
    {
        get { return this.pythonInstalled; }
        set { this.pythonInstalled = value; }
    }

    public bool ColdFusionInstalled
    {
        get { return this.coldfusionInstalled; }
        set { this.coldfusionInstalled = value; }
    }

    public bool DedicatedApplicationPool
    {
        get { return this.dedicatedApplicationPool; }
        set { this.dedicatedApplicationPool = value; }
    }

    public string ParentSiteName
    {
        get { return this.parentSiteName; }
        set { this.parentSiteName = value; }
    }

    public bool RedirectExactUrl
    {
        get { return this.redirectExactUrl; }
        set { this.redirectExactUrl = value; }
    }

    public bool RedirectDirectoryBelow
    {
        get { return this.redirectDirectoryBelow; }
        set { this.redirectDirectoryBelow = value; }
    }

    public bool RedirectPermanent
    {
        get { return this.redirectPermanent; }
        set { this.redirectPermanent = value; }
    }

    public bool CgiBinInstalled
    {
        get { return this.cgiBinInstalled; }
        set { this.cgiBinInstalled = value; }
    }

    public bool SharePointInstalled
    {
        get { return this.sharePointInstalled; }
        set { this.sharePointInstalled = value; }
    }

    public bool IIs7
    {
        get { return this.iis7; }
        set { this.iis7 = value; }
    }

    public string ConsoleUrl
    {
        get { return consoleUrl; }
        set { consoleUrl = value; }
    }

    public string Php5VersionsInstalled
    {
        get { return php5VersionsInstalled; }
        set { php5VersionsInstalled = value; }
    }
[XmlIgnore]
        public string VirtualPath
        {
            get
            {
                // virtual path is rooted
                if (String.IsNullOrEmpty(ParentSiteName))
                    return "/"; //
                else if (!Name.StartsWith("/"))
                    return "/" + Name;
                //
                return Name;
            }
        }
[XmlIgnore]
        public string FullQualifiedPath
        {
            get
            {
                if (String.IsNullOrEmpty(ParentSiteName))
                    return Name;
                else if (Name.StartsWith("/"))
                    return ParentSiteName + Name;
                else
                    return ParentSiteName + "/" + Name;
            }
        }

获取虚拟目录:

public class GetVirtualDirectories(ServerManager iismanager, string siteId)
        {
            if (!SiteExists(iismanager, siteId))
                return new SiteVirtualDirectory[] { };

            var vdirs = new List<SiteVirtualDirectory>();
            var iisObject = iismanager.Sites[siteId];
            //
            foreach (var item in iisObject.Applications)
            {
                // do not list root Virtual Directory
                if (item.Path == "/")
                    continue;
                //
                vdirs.Add(new SiteVirtualDirectory
                {
                    Name = ConfigurationUtility.GetNonQualifiedVirtualPath(item.Path),
                    ContentPath = item.VirtualDirectories[0].PhysicalPath
                });
            }
            //
            return vdirs.ToArray();
        }

0 个答案:

没有答案