当前位置: 首页>>代码示例>>C#>>正文


C# ServerManager.GetWebConfiguration方法代码示例

本文整理汇总了C#中Microsoft.Web.Administration.ServerManager.GetWebConfiguration方法的典型用法代码示例。如果您正苦于以下问题:C# ServerManager.GetWebConfiguration方法的具体用法?C# ServerManager.GetWebConfiguration怎么用?C# ServerManager.GetWebConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Web.Administration.ServerManager的用法示例。


在下文中一共展示了ServerManager.GetWebConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCustomErrors

		public void GetCustomErrors(ServerManager srvman, WebVirtualDirectory virtualDir)
		{
			var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
			//
			var httpErrorsSection = config.GetSection(Constants.HttpErrorsSection);

		    virtualDir.ErrorMode = (HttpErrorsMode)httpErrorsSection.GetAttributeValue("errorMode");
            virtualDir.ExistingResponse = (HttpErrorsExistingResponse)httpErrorsSection.GetAttributeValue("existingResponse");
			//
			var errorsCollection = httpErrorsSection.GetCollection();
			//
			var errors = new List<HttpError>();
			//
			foreach (var item in errorsCollection)
			{
				var item2Get = GetHttpError(item, virtualDir);
				//
				if (item2Get == null)
					continue;
				//
				errors.Add(item2Get);
			}
			//
			virtualDir.HttpErrors = errors.ToArray();
		}
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:25,代码来源:CustomHttpErrorsModuleService.cs

示例2: backgroundAssociatedSiteHttpRedirect_DoWork

 private void backgroundAssociatedSiteHttpRedirect_DoWork(object sender, DoWorkEventArgs e)
 {
     IEnumerable<TreeNode> selectedNoneWwwSiteNodes = e.Argument as IEnumerable<TreeNode>;
     int i = 1;
     int totalCount = selectedNoneWwwSiteNodes.Count();
     foreach (TreeNode siteNode in selectedNoneWwwSiteNodes)
     {
         if (!backgroundAssociatedSiteHttpRedirect.CancellationPending)
         {
             Node site = (Node)siteNode.Tag;
             bool enableChecked = true;
             string destination = string.Format("http://www.{0}", siteNode.Text);
             bool enableExactDestination = false;
             bool enableChildOnly = false;
             string httpResponseStatus = "永久(301)";
             try
             {
                 using (ServerManager serverManager = new ServerManager())
                 {
                     Configuration config = serverManager.GetWebConfiguration(site.Site.Name);
                     SetHttpRedirectElement(enableChecked, destination, enableExactDestination, enableChildOnly, httpResponseStatus, config);
                     string log = DateTime.Now.ToString() + ":" + string.Format("为站点 {0} 添加Http重定向,启用:{1},重定向目标:{2},定向到确切目标:{3},定向到非子目录中的内容:{4},状态代码:{5}", siteNode.Text, enableChecked, destination, enableExactDestination, enableChildOnly, httpResponseStatus);
                     backgroundAssociatedSiteHttpRedirect.ReportProgress(i * 100 / totalCount, log);
                     serverManager.CommitChanges();
                 }
             }
             catch (Exception exception)
             {
                 string log = DateTime.Now.ToString() + ":" + string.Format("为站点 {0} 添加Http重定向失败,错误详情如下", siteNode.Name) + exception.ToString();
                 backgroundSiteHttpRedirect.ReportProgress(i * 100 / totalCount, log);
             }
             i++;
         }
     }
 }
开发者ID:Brucezhang22,项目名称:IISConfiger,代码行数:35,代码来源:Form1.cs

示例3: ParseMimeTypes

    private static IDictionary<string, string> ParseMimeTypes() {
      using (var serverManager = new ServerManager()) {
        var siteName = HostingEnvironment.ApplicationHost.GetSiteName();
        var config = serverManager.GetWebConfiguration(siteName);
        var staticContentSection = config.GetSection("system.webServer/staticContent");
        var staticContentCollection = staticContentSection.GetCollection();

        var mimeMaps = staticContentCollection.Where(c =>
          c.ElementTagName == "mimeMap"
          && c.GetAttributeValue("fileExtension") != null
          && !string.IsNullOrWhiteSpace(c.GetAttributeValue("fileExtension").ToString())
          && c.GetAttributeValue("mimeType") != null
          && !string.IsNullOrWhiteSpace(c.GetAttributeValue("mimeType").ToString())
        );
        var results = mimeMaps.Select(m => new KeyValuePair<string, string>(m.GetAttributeValue("fileExtension").ToString(), m.GetAttributeValue("mimeType").ToString()));
        return results.ToDictionary(pair => pair.Key, pair => pair.Value);
      }
    }
开发者ID:njmube,项目名称:N2.S3FileSystem,代码行数:18,代码来源:MimeExtractor.cs

示例4: AlterWebConfig

        protected void AlterWebConfig()
        {
            Configuration appHost = IISManager.GetApplicationHostConfiguration();
            ConfigurationSection configPaths = appHost.GetSection("connectionstring");
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetWebConfiguration("TestSite");

                ConfigurationSection directoryBrowseSection =
                    config.GetSection("system.webServer/directoryBrowse");

                if ((bool)directoryBrowseSection["enabled"] != true)
                {
                    directoryBrowseSection["enabled"] = true;
                }

                serverManager.CommitChanges();
            }
        }
开发者ID:modulexcite,项目名称:WebSiteManager,代码行数:19,代码来源:SiteAdmin.aspx.cs

示例5: GetMimeMaps

		/// <summary>
		/// Loads available mime maps into supplied virtual iisDirObject description.
		/// </summary>
		/// <param name="vdir">Virtual iisDirObject description.</param>
		public void GetMimeMaps(ServerManager srvman, WebVirtualDirectory virtualDir)
		{
			var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
			//
			var section = config.GetSection(Constants.StaticContentSection);
			//
			var mappings = new List<MimeMap>();
			//
			foreach (var item in section.GetCollection())
			{
				var item2Get = GetMimeMap(item);
				//
				if (item2Get == null)
					continue;
				//
				mappings.Add(item2Get);
			}
			//
			virtualDir.MimeMaps = mappings.ToArray();
		}
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:24,代码来源:MimeTypesModuleService.cs

示例6: Delete

        public ActionResult Delete(String id)
        {
            using (var serverManager = new ServerManager(Environment.ExpandEnvironmentVariables(@"%APP_POOL_CONFIG%")))
            {
                var path = @"Web.config";

                var sites = serverManager.Sites;

                var webConfig = serverManager.GetWebConfiguration(webSiteName);
                string rulesSection = "rules";
                var inboundRulesCollection =
                    webConfig.GetSection("system.webServer/rewrite/" + rulesSection).GetCollection();

                var ruleToDelete = inboundRulesCollection.FirstOrDefault(i => i.GetAttribute("name").Value.ToString() == id);
                if(ruleToDelete != null)
                    inboundRulesCollection.Remove(ruleToDelete);

                serverManager.CommitChanges();
            }

            return RedirectToAction("Index");
        }
开发者ID:jdevillard,项目名称:AzureProxyAdminConsole,代码行数:22,代码来源:ConfigureController.cs

示例7: GetDefaultDocumentSettings

		public string GetDefaultDocumentSettings(ServerManager srvman, string siteId)
		{
			// Load web site configuration
			var config = srvman.GetWebConfiguration(siteId);
			// Load corresponding section
			var section = config.GetSection(Constants.DefaultDocumentsSection);
			//
			var filesCollection = section.GetCollection("files");
			// Build default documents
			var defaultDocs = new List<String>();
			//
			foreach (var item in filesCollection)
			{
				var item2Get = GetDefaultDocument(item);
				//
				if (String.IsNullOrEmpty(item2Get))
					continue;
				//
				defaultDocs.Add(item2Get);
			}
			//
			return String.Join(",", defaultDocs.ToArray());
		}
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:23,代码来源:DefaultDocumentModuleService.cs

示例8: Create

        public ActionResult Create(ConfigModel model)
        {
            using (var serverManager = new ServerManager(Environment.ExpandEnvironmentVariables(@"%APP_POOL_CONFIG%")))
            {
                var path = @"Web.config";

                var sites = serverManager.Sites;

                var webConfig = serverManager.GetWebConfiguration(webSiteName);
                string rulesSection = "rules";
                var inboundRulesCollection =
                    webConfig.GetSection("system.webServer/rewrite/" + rulesSection).GetCollection();
                var outboundRulesSection = webConfig.GetSection("system.webServer/rewrite/outboundRules");
                var outbBoundRulesCollection = outboundRulesSection.GetCollection();
                var preConditionsCollection = outboundRulesSection.GetCollection("preConditions");

                inboundRulesCollection.AddAt(inboundRulesCollection.Count - 1,
                CreateInboundGwRemoteUserRule(model, inboundRulesCollection.CreateElement("rule")));

                serverManager.CommitChanges();
            }

            return RedirectToAction("Index");
        }
开发者ID:jdevillard,项目名称:AzureProxyAdminConsole,代码行数:24,代码来源:ConfigureController.cs

示例9: Index

        // GET: Configure
        public ActionResult Index()
        {
            var list = new List<ConfigModel>();

            using (var serverManager = new ServerManager(Environment.ExpandEnvironmentVariables(@"%APP_POOL_CONFIG%")))
            {
                var path = @"Web.config";

                var sites = serverManager.Sites;

                var webConfig = serverManager.GetWebConfiguration(webSiteName);
                string rulesSection = "rules";
                var inboundRulesCollection =
                    webConfig.GetSection("system.webServer/rewrite/" + rulesSection).GetCollection();
                var outboundRulesSection = webConfig.GetSection("system.webServer/rewrite/outboundRules");
                var outboundRulesCollection = outboundRulesSection.GetCollection();
                var preConditionsCollection = outboundRulesSection.GetCollection("preConditions");

                inboundRulesCollection.ForEach(
                    r =>
                    {
                        var conditions = r.GetCollection("conditions");
                        var condition = conditions.FirstOrDefault(c => c.GetAttribute("input").Value.ToString() == "{HTTP_HOST}");

                        list.Add(new ConfigModel()
                        {
                            RuleName = r.GetAttribute("name").Value.ToString(),
                            Pattern = condition != null ? condition.GetAttribute("pattern").Value.ToString() : string.Empty,

                        });
                    })
                    ;

            }
            return View(list);
        }
开发者ID:jdevillard,项目名称:AzureProxyAdminConsole,代码行数:37,代码来源:ConfigureController.cs

示例10: GetConfigModelFromId

        private static ConfigModel GetConfigModelFromId(string id)
        {
            ConfigModel model;
            using (var serverManager = new ServerManager(Environment.ExpandEnvironmentVariables(@"%APP_POOL_CONFIG%")))
            {
                var path = @"Web.config";

                var sites = serverManager.Sites;

                var webConfig = serverManager.GetWebConfiguration(webSiteName);
                string rulesSection = "rules";
                var inboundRulesCollection =
                    webConfig.GetSection("system.webServer/rewrite/" + rulesSection).GetCollection();
                var outboundRulesSection = webConfig.GetSection("system.webServer/rewrite/outboundRules");
                var outboundRulesCollection = outboundRulesSection.GetCollection();
                var preConditionsCollection = outboundRulesSection.GetCollection("preConditions");

                var rule = inboundRulesCollection.First(
                    r => r.GetAttribute("name").Value.ToString() == id);

                var conditions = rule.GetCollection("conditions");
                var condition = conditions.FirstOrDefault(c => c.GetAttribute("input").Value.ToString() == "{HTTP_HOST}");

                var action = rule.GetChildElement("action");

                model = new ConfigModel()
                {
                    Pattern = condition != null ? condition.GetAttribute("pattern").Value.ToString() : string.Empty,
                    RuleName = id,
                    UrlRewrite = action.GetAttributeValue("url").ToString()
                };
            }
            return model;
        }
开发者ID:jdevillard,项目名称:AzureProxyAdminConsole,代码行数:34,代码来源:ConfigureController.cs

示例11: SetHandlersAccessPolicy

		public void SetHandlersAccessPolicy(ServerManager srvman, string fqPath, HandlerAccessPolicy policy)
		{
			var config = srvman.GetWebConfiguration(fqPath);
			//
			HandlersSection section = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection));
			//
			section.AccessPolicy = policy;
		}
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:8,代码来源:HandlersModuleService.cs

示例12: SetAuthenticationSection

        private static void SetAuthenticationSection(string attributeName, string value)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                Site site = serverManager.Sites.Where(s => s.Name == IISHelper.DefaultWebSiteName).Single();
                Configuration config = serverManager.GetWebConfiguration(site.Name);
                ConfigurationSection authenticationSection =
                             config.GetSection("system.web/authentication");

                authenticationSection.SetAttributeValue(attributeName, value);
                serverManager.CommitChanges();
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:13,代码来源:IISHelper.cs

示例13: GetPhpVersions

	    protected PhpVersion[] GetPhpVersions(ServerManager srvman, WebVirtualDirectory virtualDir)
	    {
	        var config = srvman.GetWebConfiguration(GetSiteIdFromVirtualDir(virtualDir), virtualDir.VirtualPath);
	        //var config = srvman.GetApplicationHostConfiguration();
	        var handlersSection = config.GetSection(Constants.HandlersSection);

	        var result = new List<PhpVersion>();

	        // Loop through available maps and fill installed processors
	        foreach (var handler in handlersSection.GetCollection())
	        {
	            if (string.Equals(handler["path"].ToString(), "*.php", StringComparison.OrdinalIgnoreCase))
	            {
	                var executable = handler["ScriptProcessor"].ToString().Split('|')[0];
	                if (string.Equals(handler["Modules"].ToString(), "FastCgiModule", StringComparison.OrdinalIgnoreCase) && File.Exists(executable))
	                {
	                    var handlerName = handler["Name"].ToString();
	                    result.Add(new PhpVersion() {HandlerName = handlerName, Version = GetPhpExecutableVersion(executable), ExecutionPath = handler["ScriptProcessor"].ToString()});
	                }
	            }
	        }

	        return result.ToArray();
	    }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:24,代码来源:IIs70.cs

示例14: FillVirtualDirectoryRestFromIISObject

        private void FillVirtualDirectoryRestFromIISObject(ServerManager srvman, WebVirtualDirectory virtualDir)
        {
            // HTTP REDIRECT
            httpRedirectSvc.GetHttpRedirectSettings(srvman, virtualDir);

            // HTTP HEADERS
            customHeadersSvc.GetCustomHttpHeaders(srvman, virtualDir);

            // HTTP ERRORS
            customErrorsSvc.GetCustomErrors(srvman, virtualDir);

            // MIME MAPPINGS
            mimeTypesSvc.GetMimeMaps(srvman, virtualDir);

            // SCRIPT MAPS
            // Load installed script maps.

            virtualDir.AspInstalled = false; // not installed
            virtualDir.PhpInstalled = ""; // none
            virtualDir.PerlInstalled = false; // not installed
            virtualDir.PythonInstalled = false; // not installed
            virtualDir.ColdFusionInstalled = false; // not installed
            //
            var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
            var handlersSection = config.GetSection(Constants.HandlersSection);

            // Loop through available maps and fill installed processors
            foreach (ConfigurationElement action in handlersSection.GetCollection())
            {
                // Extract and evaluate scripting processor path
                string processor = FileUtils.EvaluateSystemVariables(
                    Convert.ToString(action.GetAttributeValue("scriptProcessor")));
                //
                string actionName = Convert.ToString(action.GetAttributeValue("name"));

                // Detect whether ASP scripting is enabled
                if (!String.IsNullOrEmpty(AspPath) && String.Equals(AspPath, processor, StringComparison.InvariantCultureIgnoreCase))
                    virtualDir.AspInstalled = true;

                //// Detect whether PHP 5 scripting is enabled (non fast_cgi)
                if (PhpMode != Constants.PhpMode.FastCGI && !String.IsNullOrEmpty(PhpExecutablePath) && String.Equals(PhpExecutablePath, processor, StringComparison.InvariantCultureIgnoreCase))
                    virtualDir.PhpInstalled = PHP_5;

                // Detect whether PHP 4 scripting is enabled
                if (!String.IsNullOrEmpty(Php4Path) && String.Equals(Php4Path, processor, StringComparison.InvariantCultureIgnoreCase))
                    virtualDir.PhpInstalled = PHP_4;

                // Detect whether ColdFusion scripting is enabled
                if (!String.IsNullOrEmpty(ColdFusionPath) && String.Compare(ColdFusionPath, processor, true) == 0 && actionName.Contains(".cfm"))
                    virtualDir.ColdFusionInstalled = true;

                // Detect whether Perl scripting is enabled
                if (!String.IsNullOrEmpty(PerlPath) && String.Equals(PerlPath, processor, StringComparison.InvariantCultureIgnoreCase))
                    virtualDir.PerlInstalled = true;
            }

            // Detect PHP 5 Fast_cgi version(s)
            var activePhp5Handler = GetActivePhpHandlerName(srvman, virtualDir);
            if (!string.IsNullOrEmpty(activePhp5Handler))
            {
                virtualDir.PhpInstalled = PHP_5 + "|" + activePhp5Handler;
                var versions = GetPhpVersions(srvman, virtualDir);
                // This versionstring is used in UI to view and change php5 version.
                var versionString = string.Join("|", versions.Select(v => v.HandlerName + ";" + v.Version).ToArray());
                virtualDir.Php5VersionsInstalled = versionString;
            }

            //
            string fqPath = virtualDir.FullQualifiedPath;
            if (!fqPath.EndsWith(@"/"))
                fqPath += "/";
            //
            fqPath += CGI_BIN_FOLDER;
            //
            HandlerAccessPolicy policy = handlersSvc.GetHandlersAccessPolicy(srvman, fqPath);
            virtualDir.CgiBinInstalled = (policy & HandlerAccessPolicy.Execute) > 0;

            // ASP.NET
            FillAspNetSettingsFromIISObject(srvman, virtualDir);
        }
开发者ID:jonwbstr,项目名称:Websitepanel,代码行数:80,代码来源:IIs70.cs

示例15: GetActivePhpHandlerName

        protected string GetActivePhpHandlerName(ServerManager srvman, WebVirtualDirectory virtualDir)
        {
            var config = srvman.GetWebConfiguration(GetSiteIdFromVirtualDir(virtualDir), virtualDir.VirtualPath);
            var handlersSection = config.GetSection(Constants.HandlersSection);

            // Find first handler for *.php
            return (from handler in handlersSection.GetCollection()
                    where string.Equals(handler["path"].ToString(), "*.php", StringComparison.OrdinalIgnoreCase) &&  string.Equals(handler["Modules"].ToString(), "FastCgiModule", StringComparison.OrdinalIgnoreCase)
                    select handler["name"].ToString()
                    ).FirstOrDefault();
        }
开发者ID:jonwbstr,项目名称:Websitepanel,代码行数:11,代码来源:IIs70.cs


注:本文中的Microsoft.Web.Administration.ServerManager.GetWebConfiguration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。