internal static void WriteHandlerToConfiguration(Configuration config) { HttpHandlersSection handlers = config.GetSection("system.web/httpHandlers") as HttpHandlersSection; foreach (HttpHandlerAction h in handlers.Handlers) { if (h.Path == HandlerName) { return; } } HttpHandlerAction myHandler = new HttpHandlerAction(HandlerName, HandlerType, "*", false); handlers.Handlers.Add(myHandler); try { config.Save(); } catch (Exception ex) { // Gulp System.Diagnostics.Debug.Write(ex.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { string typeName = typeof(HttpRequest).AssemblyQualifiedName .Replace("HttpRequest", "Configuration.RuntimeConfig"); Type type = Type.GetType(typeName); bool useAppConfig = Request.QueryString["useAppConfig"] == "1"; // 由于RuntimeConfig类型的可见性是internal, // 所以,我不能直接用它声明变量,只能使用object类型 object config = null; if (useAppConfig) config = type.InvokeMember("GetAppConfig", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, null); else config = type.InvokeMember("GetConfig", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[] { this.Context }); HttpHandlersSection section = (HttpHandlersSection)type.InvokeMember("HttpHandlers", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, config, null); HttpHandlers = string.Format("总共 {0} 个配置项。<br />", section.Handlers.Count) + string.Join("<br />", ( from h in section.Handlers.Cast<HttpHandlerAction>() let action = string.Format("path=\"{0}\" verb=\"{1}\" validate=\"{2}\" type=\"{3}\"", h.Path, h.Verb, h.Validate, h.Type) select action).ToArray()); }
public ActionResult HttpHandles() { HttpHandlersSection section = GetConfigSetting <HttpHandlersSection>("HttpHandlers"); var httpHandlers = from h in section.Handlers.Cast <HttpHandlerAction>() let action = $"path=\"{h.Path}\" verb=\"{h.Verb}\" validate=\"{h.Validate}\" type=\"{h.Type}\"" select action; return(View("HttpView", httpHandlers)); }
bool LocateHandler(string verb, string uri) { HttpHandlersSection config = WebConfigurationManager.GetSection("system.web/httpHandlers") as HttpHandlersSection; HttpHandlerActionCollection handlers = config != null ? config.Handlers : null; int count = handlers != null ? handlers.Count : 0; if (count == 0) { return(false); } HttpHandlerAction handler; string[] verbs; for (int i = 0; i < count; i++) { handler = handlers [i]; verbs = SplitVerbs(handler.Verb); if (verbs == null) { if (PathMatches(handler, uri)) { return(true); } continue; } for (int j = 0; j < verbs.Length; j++) { if (verbs [j] != verb) { continue; } if (PathMatches(handler, uri)) { return(true); } } } return(false); }
/// <summary>获取httpHandlers</summary> /// <returns></returns> public static List <HttpHandlerAction> GethttpHandlers() { List <HttpHandlerAction> value = new List <HttpHandlerAction>(); HttpHandlersSection httphanset = httpHandlers as HttpHandlersSection; if (httphanset == null) { return(value); } ConfigurationElementCollection cec = (ConfigurationElementCollection)httphanset.Handlers; for (Int32 i = 0; i < cec.Count; i++) { value.Add(httphanset.Handlers[i]); } return(value); }
///<summary> /// Change the Web.Config and add this to the http handlers section ///</summary> public static void ModifyWebConfig() { Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~"); var systemWeb = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); if (systemWeb != null) { HttpHandlersSection httpHandlers = systemWeb.HttpHandlers; if (httpHandlers != null) { if (httpHandlers.Handlers.Cast <HttpHandlerAction>().Any(action => action.Path == "CommandHandler.axd")) { return; } httpHandlers.Handlers.Add( new HttpHandlerAction("CommandHandler.axd", typeof(CommandHandler).FullName, "GET,HEAD")); configuration.Save(); } } }
private IEnumerable <ConfigurationHttpHandlersModel> ProcessHttpHandler(HttpHandlersSection httpHandlersSection) { if (httpHandlersSection == null) { return(null); } var result = new List <ConfigurationHttpHandlersModel>(); foreach (HttpHandlerAction httpModule in httpHandlersSection.Handlers) { var resultItem = new ConfigurationHttpHandlersModel(); resultItem.Path = httpModule.Path; resultItem.Verb = httpModule.Verb; resultItem.Validate = httpModule.Validate; resultItem.Type = httpModule.Type; result.Add(resultItem); } return(result); }
internal static void CheckConfiguration(ISite site) { if (site == null) { return; } IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication)); if (app == null) { return; } Configuration config = app.OpenWebConfiguration(false); HttpHandlersSection handlers = (HttpHandlersSection)config.GetSection("system.web/httpHandlers"); // Does the httpHandlers Secton already exist? if (handlers == null) { // If not, add it... handlers = new HttpHandlersSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpHandlers", handlers); } } HttpHandlerAction action = new HttpHandlerAction("*/ext.axd", "Ext.Net.ResourceHandler", "*", false); // Does the ResourceHandler already exist? if (handlers.Handlers.IndexOf(action) < 0) { // If not, add it... handlers.Handlers.Add(action); config.Save(); } HttpModulesSection modules = (HttpModulesSection)config.GetSection("system.web/httpModules"); // Does the httpModules Secton already exist? if (modules == null) { // If not, add it... modules = new HttpModulesSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpModules", modules); } } //<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" /> HttpModuleAction action2 = new HttpModuleAction("DirectRequestModule", "Ext.Net.DirectRequestModule, Ext.Net"); // Does the ResourceHandler already exist? if (modules.Modules.IndexOf(action2) < 0) { // If not, add it... modules.Modules.Add(action2); config.Save(); } }
public void RunDeploy(String[] args) { if (args.Length < 3) { Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -deploy mode, type rdfWebDeploy -help to see usage summary"); return; } if (args.Length > 3) { if (!this.SetOptions(args.Skip(3).ToArray())) { Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid"); return; } } if (this._noLocalIIS) { Console.WriteLine("rdfWebDeploy: No Local IIS Server available so switching to -xmldeploy mode"); XmlDeploy xdeploy = new XmlDeploy(); xdeploy.RunXmlDeploy(args); return; } //Define the Server Manager object Admin.ServerManager manager = null; try { //Connect to the Server Manager if (!this._noIntegratedRegistration) { manager = new Admin.ServerManager(); } //Open the Configuration File System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site); Console.Out.WriteLine("rdfWebDeploy: Opened the Web.config file for the specified Web Application"); //Detect Folders String appFolder = Path.GetDirectoryName(config.FilePath); String binFolder = Path.Combine(appFolder, "bin\\"); String appDataFolder = Path.Combine(appFolder, "App_Data\\"); if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application"); } if (!Directory.Exists(appDataFolder)) { Directory.CreateDirectory(appDataFolder); Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application"); } //Deploy dotNetRDF and required DLLs to the bin directory of the application String sourceFolder = RdfWebDeployHelper.ExecutablePath; IEnumerable <String> dlls = RdfWebDeployHelper.RequiredDLLs; if (this._sql) { dlls = dlls.Concat(RdfWebDeployHelper.RequiredSqlDLLs); } if (this._virtuoso) { dlls = dlls.Concat(RdfWebDeployHelper.RequiredVirtuosoDLLs); } if (this._fulltext) { dlls = dlls.Concat(RdfWebDeployHelper.RequiredFullTextDLLs); } foreach (String dll in dlls) { if (File.Exists(Path.Combine(sourceFolder, dll))) { File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true); Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found"); return; } } //Deploy the configuration file to the App_Data directory if (File.Exists(args[2])) { File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true); Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory"); } else if (!File.Exists(Path.Combine(appDataFolder, args[2]))) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder"); return; } //Set the AppSetting for the configuration file config.AppSettings.Settings.Remove("dotNetRDFConfig"); config.AppSettings.Settings.Add("dotNetRDFConfig", "~/App_Data/" + Path.GetFileName(args[2])); Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\""); //Now load the Configuration Graph from the App_Data folder Graph g = new Graph(); FileLoader.Load(g, Path.Combine(appDataFolder, args[2])); Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings"); Console.WriteLine(); //Get the sections of the Configuration File we want to edit HttpHandlersSection handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection; if (handlersSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Handlers section of the web applications Web.Config file"); return; } //Detect Handlers from the Configution Graph and deploy IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode dnrType = g.CreateUriNode(new Uri(ConfigurationLoader.PropertyType)); IUriNode httpHandler = g.CreateUriNode(new Uri(ConfigurationLoader.ClassHttpHandler)); //Deploy for IIS Classic Mode if (!this._noClassicRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode"); foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //First remove any existing registration handlersSection.Handlers.Remove("*", handlerPath); //Then add the new registration handlersSection.Handlers.Add(new HttpHandlerAction(handlerPath, handlerType, "*")); Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } } //Deploy Negotiate by File Extension if appropriate if (this._negotiate) { HttpModulesSection modulesSection = config.GetSection("system.web/httpModules") as HttpModulesSection; if (modulesSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file"); return; } modulesSection.Modules.Remove("NegotiateByExtension"); modulesSection.Modules.Add(new HttpModuleAction("NegotiateByExtension", "VDS.RDF.Web.NegotiateByFileExtension")); Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode"); } //Save the completed Configuration File config.Save(ConfigurationSaveMode.Minimal); Console.WriteLine(); //Deploy for IIS Integrated Mode if (!this._noIntegratedRegistration) { Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode"); Admin.Configuration adminConfig = manager.GetWebConfiguration(this._site, args[1]); Admin.ConfigurationSection newHandlersSection = adminConfig.GetSection("system.webServer/handlers"); Admin.ConfigurationElementCollection newHandlers = newHandlersSection.GetCollection(); foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject)) { if (n.NodeType == NodeType.Uri) { String handlerPath = ((IUriNode)n).Uri.AbsolutePath; INode type = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault(); if (type == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified"); continue; } if (type.NodeType == NodeType.Literal) { String handlerType = ((ILiteralNode)type).Value; //First remove any existing registration foreach (Admin.ConfigurationElement oldReg in newHandlers.Where(el => el.GetAttributeValue("name").Equals(handlerPath)).ToList()) { newHandlers.Remove(oldReg); } //Then add the new registration Admin.ConfigurationElement reg = newHandlers.CreateElement("add"); reg["name"] = handlerPath; reg["path"] = handlerPath; reg["verb"] = "*"; reg["type"] = handlerType; newHandlers.AddAt(0, reg); Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file"); } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal"); continue; } } else { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node"); } //Deploy Negotiate by File Extension if appropriate if (this._negotiate) { Admin.ConfigurationSection newModulesSection = adminConfig.GetSection("system.webServer/modules"); if (newModulesSection == null) { Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file"); return; } //First remove the Old Module Admin.ConfigurationElementCollection newModules = newModulesSection.GetCollection(); foreach (Admin.ConfigurationElement oldReg in newModules.Where(el => el.GetAttribute("name").Equals("NegotiateByExtension")).ToList()) { newModules.Remove(oldReg); } //Then add the new Module Admin.ConfigurationElement reg = newModules.CreateElement("add"); reg["name"] = "NegotiateByExtension"; reg["type"] = "VDS.RDF.Web.NegotiateByFileExtension"; newModules.AddAt(0, reg); Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module"); } } manager.CommitChanges(); Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode"); } } catch (ConfigurationException configEx) { Console.Error.WriteLine("rdfWebDeploy: Configuration Error: " + configEx.Message); } catch (Exception ex) { Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message); Console.Error.WriteLine(ex.StackTrace); } finally { if (manager != null) { manager.Dispose(); } } }
static void Main(string[] args) { string inputStr = String.Empty; string option = String.Empty; // Define a regular expression to allow only // alphanumeric inputs that are at most 20 character // long. For instance "/iii:". Regex rex = new Regex(@"[^\/w]{1,20}:"); // Parse the user's input. if (args.Length < 1) { // No option entered. Console.Write("Input parameter missing."); return; } else { // Get the user's option. inputStr = args[0].ToLower(); if (!(rex.Match(inputStr)).Success) { // Wrong option format used. Console.Write("Input parameter format not allowed."); return; } } // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration( "/aspnetTest"); // Get the <system.web> group. SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); // </Snippet1> try { switch (inputStr) { case "/anonymous:": // <Snippet2> // Get the anonymousIdentification section. AnonymousIdentificationSection anonymousIdentification = systemWeb.AnonymousIdentification; // Read section information. info = anonymousIdentification.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet2> Console.Write(msg); break; case "/authentication:": // <Snippet3> // Get the authentication section. AuthenticationSection authentication = systemWeb.Authentication; // Read section information. info = authentication.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet3> Console.Write(msg); break; case "/authorization:": // <Snippet4> // Get the authorization section. AuthorizationSection authorization = systemWeb.Authorization; // Read section information. info = authorization.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet4> Console.Write(msg); break; case "/compilation:": // <Snippet5> // Get the compilation section. CompilationSection compilation = systemWeb.Compilation; // Read section information. info = compilation.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet5> Console.Write(msg); break; case "/customerrors:": // <Snippet6> // Get the customerrors section. CustomErrorsSection customerrors = systemWeb.CustomErrors; // Read section information. info = customerrors.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet6> Console.Write(msg); break; case "/globalization:": // <Snippet7> // Get the globalization section. GlobalizationSection globalization = systemWeb.Globalization; // Read section information. info = globalization.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet7> Console.Write(msg); break; case "/httpcookies:": // <Snippet8> // Get the httpCookies section. HttpCookiesSection httpCookies = systemWeb.HttpCookies; // Read section information. info = httpCookies.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet8> Console.Write(msg); break; case "/httphandlers:": // <Snippet9> // Get the httpHandlers section. HttpHandlersSection httpHandlers = systemWeb.HttpHandlers; // Read section information. info = httpHandlers.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet9> Console.Write(msg); break; case "/httpmodules:": // <Snippet10> // Get the httpModules section. HttpModulesSection httpModules = systemWeb.HttpModules; // Read section information. info = httpModules.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet10> Console.Write(msg); break; case "/httpruntime:": // <Snippet11> // Get the httpRuntime section. HttpRuntimeSection httpRuntime = systemWeb.HttpRuntime; // Read section information. info = httpRuntime.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet11> Console.Write(msg); break; case "/identity:": // <Snippet12> // Get the identity section. IdentitySection identity = systemWeb.Identity; // Read section information. info = identity.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet12> Console.Write(msg); break; case "/machinekey:": // <Snippet13> // Get the machineKey section. MachineKeySection machineKey = systemWeb.MachineKey; // Read section information. info = machineKey.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet13> Console.Write(msg); break; case "/membership:": // <Snippet14> // Get the membership section. MembershipSection membership = systemWeb.Membership; // Read section information. info = membership.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet14> Console.Write(msg); break; case "/pages:": // <Snippet15> // Get the pages section. PagesSection pages = systemWeb.Pages; // Read section information. info = pages.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet15> Console.Write(msg); break; case "/processModel:": // <Snippet16> // Get the processModel section. ProcessModelSection processModel = systemWeb.ProcessModel; // Read section information. info = processModel.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet16> Console.Write(msg); break; case "/profile:": // <Snippet17> // Get the profile section. ProfileSection profile = systemWeb.Profile; // Read section information. info = profile.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet17> Console.Write(msg); break; case "/roleManager:": // <Snippet18> // Get the roleManager section. RoleManagerSection roleManager = systemWeb.RoleManager; // Read section information. info = roleManager.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet18> Console.Write(msg); break; case "/securityPolicy:": // <Snippet19> // Get the securityPolicy section. SecurityPolicySection securityPolicy = systemWeb.SecurityPolicy; // Read section information. info = securityPolicy.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet19> Console.Write(msg); break; case "/sessionState:": // <Snippet20> // Get the sessionState section. SessionStateSection sessionState = systemWeb.SessionState; // Read section information. info = sessionState.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet20> Console.Write(msg); break; case "/sitemap:": // <Snippet21> // Get the siteMap section. SiteMapSection siteMap = systemWeb.SiteMap; // Read section information. info = siteMap.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet21> Console.Write(msg); break; case "/trace:": // <Snippet22> // Get the trace section. TraceSection trace = systemWeb.Trace; // Read section information. info = trace.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet22> Console.Write(msg); break; case "/trust:": // <Snippet23> // Get the trust section. TrustSection trust = systemWeb.Trust; // Read section information. info = trust.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet23> Console.Write(msg); break; case "/browserCaps:": // <Snippet24> // Get the browserCaps section. DefaultSection browserCaps = systemWeb.BrowserCaps; // Read section information. info = browserCaps.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet24> Console.Write(msg); break; case "/clientTarget:": // <Snippet25> // Get the clientTarget section. ClientTargetSection clientTarget = systemWeb.ClientTarget; // Read section information. info = clientTarget.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet25> Console.Write(msg); break; case "/deployment:": // <Snippet26> // Get the deployment section. DeploymentSection deployment = systemWeb.Deployment; // Read section information. info = deployment.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet26> Console.Write(msg); break; case "/deviceFilters:": // <Snippet27> // Get the deviceFilters section. DefaultSection deviceFilters = systemWeb.DeviceFilters; // Read section information. info = deviceFilters.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet27> Console.Write(msg); break; case "/healthMonitoring:": // <Snippet28> // Get the healthMonitoring section. HealthMonitoringSection healthMonitoring = systemWeb.HealthMonitoring; // Read section information. info = healthMonitoring.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet28> Console.Write(msg); break; case "/hostingEnvironment:": // <Snippet29> // Get the hostingEnvironment section. HostingEnvironmentSection hostingEnvironment = systemWeb.HostingEnvironment; // Read section information. info = hostingEnvironment.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet29> Console.Write(msg); break; case "/mobileControls:": // <Snippet30> // Get the mobileControls section. ConfigurationSection mobileControls = systemWeb.MobileControls; // Read section information. info = mobileControls.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet30> Console.Write(msg); break; case "/protocols:": // <Snippet31> // Get the protocols section. DefaultSection protocols = systemWeb.Protocols; // Read section information. info = protocols.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet31> Console.Write(msg); break; case "/urlMappings:": // <Snippet32> // Get the urlMappings section. UrlMappingsSection urlMappings = systemWeb.UrlMappings; // Read section information. info = urlMappings.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet32> Console.Write(msg); break; case "/webControls:": // <Snippet33> // Get the webControls section. WebControlsSection webControls = systemWeb.WebControls; // Read section information. info = webControls.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet33> Console.Write(msg); break; case "/webParts:": // <Snippet34> // Get the webParts section. WebPartsSection webParts = systemWeb.WebParts; // Read section information. info = webParts.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet34> Console.Write(msg); break; case "/webServices:": // <Snippet35> // Get the webServices section. WebServicesSection webServices = systemWeb.WebServices; // Read section information. info = webServices.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet35> Console.Write(msg); break; case "/XhtmlConformance:": // <Snippet36> // Get the xhtmlConformance section. XhtmlConformanceSection xhtmlConformance = systemWeb.XhtmlConformance; // Read section information. info = xhtmlConformance.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet36> Console.Write(msg); break; case "/all:": StringBuilder allSections = new StringBuilder(); ConfigurationSectionGroup systemWebGroup = configuration.GetSectionGroup("system.web"); int i = 0; foreach (ConfigurationSection section in systemWebGroup.Sections) { i += 1; info = section.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); if (i < 10) { msg = String.Format( "{0})Name: {1}\nDeclared: {2}\nType: {3}\n", i.ToString(), name, declared, type); } else { msg = String.Format( "{0})Name: {1}\nDeclared: {2}\nType: {3}\n", i.ToString(), name, declared, type); } allSections.AppendLine(msg); } // Console.WriteLine(systemWebGroup.Name); // Console.WriteLine(systemWebGroup.SectionGroupName); Console.Write(allSections.ToString()); break; default: // Option is not allowed.. Console.Write("Input not allowed."); break; } } catch (ArgumentException e) { // Never display this. Use it for // debugging purposes. msg = e.ToString(); } }
public virtual void SystemWeb() { #if !ClientSKUFramework // update MaxRequestLength in system.web/httpRuntime section HttpRuntimeSection httpRuntimeSection = (HttpRuntimeSection)config.GetSection("system.web/httpRuntime"); httpRuntimeSection.MaxRequestLength = _MaxRequestLength; // update system.web/trust TrustSection trustSection = (TrustSection)config.GetSection("system.web/trust"); trustSection.SectionInformation.SetRawXml(string.Format(trustSection.SectionInformation.GetRawXml(), _TrustLevel)); CompilationSection compilationSection = (CompilationSection)config.GetSection("system.web/compilation"); // update system.web/compilation/debug compilationSection.Debug = _CompilationDebug; // update assembly strings in system.web/compilation section foreach (AssemblyInfo assemblyItem in compilationSection.Assemblies) { var version = assemblyItem.Assembly.StartsWith("System.Data.Entity") ? _EntityAssemblyVersion : _AssemblyVersion; if (assemblyItem.Assembly.Contains("Test")) { // Test assemblies have the same version version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); } assemblyItem.Assembly = String.Format(assemblyItem.Assembly, version, _AssemblyDomain, _AssemblyDomainVersion, _AssemblyPublicKeyToken); } // Setup the correct buildProvider settings if necessary bool shouldOverrideMachineWebConfigSettings = ShouldOverrideExistingBuildProviderSettings(_AssemblyDomain, _AssemblyDomainVersion, _AssemblyPublicKeyToken); if (shouldOverrideMachineWebConfigSettings) { // update the handler versions compilationSection.FolderLevelBuildProviders.Clear(); var folderLevelBuildProvider = new FolderLevelBuildProvider("DataServiceBuildProvider", "Microsoft.OData.Service.BuildProvider.DataServiceBuildProvider"); compilationSection.FolderLevelBuildProviders.Add(folderLevelBuildProvider); } // update authentication mode in system.web/authentication AuthenticationSection authenticationSection = (AuthenticationSection)config.GetSection("system.web/authentication"); switch (_AuthMode.ToLower()) { case "forms": authenticationSection.Mode = System.Web.Configuration.AuthenticationMode.Forms; break; case "passport": authenticationSection.Mode = System.Web.Configuration.AuthenticationMode.Passport; break; case "windows": authenticationSection.Mode = System.Web.Configuration.AuthenticationMode.Windows; break; default: authenticationSection.Mode = System.Web.Configuration.AuthenticationMode.None; break; } // update httpHandler versions in system.web/httpHandlers section HttpHandlersSection httpHandlersSection = (HttpHandlersSection)config.GetSection("system.web/httpHandlers"); foreach (HttpHandlerAction httpHandler in httpHandlersSection.Handlers) { httpHandler.Type = String.Format(httpHandler.Type, _AssemblyVersion); } #endif }