Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Configuration / WebConfigurationManager.cs / 1305376 / WebConfigurationManager.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Configuration { using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Security; using System.Security.Permissions; using System.Web.Hosting; public static class WebConfigurationManager { public static NameValueCollection AppSettings { get { return ConfigurationManager.AppSettings; } } public static ConnectionStringSettingsCollection ConnectionStrings { get { return ConfigurationManager.ConnectionStrings; } } public static object GetSection(string sectionName) { if (HttpConfigurationSystem.UseHttpConfigurationSystem) { return HttpConfigurationSystem.GetSection(sectionName); } else { return ConfigurationManager.GetSection(sectionName); } } public static object GetSection(string sectionName, string path) { if (HttpConfigurationSystem.UseHttpConfigurationSystem) { return HttpConfigurationSystem.GetSection(sectionName, path); } else { throw new InvalidOperationException(SR.GetString(SR.Config_GetSectionWithPathArgInvalid)); } } public static object GetWebApplicationSection(string sectionName) { if (HttpConfigurationSystem.UseHttpConfigurationSystem) { return HttpConfigurationSystem.GetApplicationSection(sectionName); } else { return ConfigurationManager.GetSection(sectionName); } } // // ************************************************* // ** Static Management Functions to edit config ** // ************************************************* // private static Configuration OpenWebConfigurationImpl( WebLevel webLevel, ConfigurationFileMap fileMap, string path, string site, string locationSubPath, string server, string userName, string password, IntPtr userToken) { // In the hosted case, we allow app relative (~/....). Otherwise, it must be absolute VirtualPath virtualPath; if (HostingEnvironment.IsHosted) { virtualPath = VirtualPath.CreateNonRelativeAllowNull(path); } else { virtualPath = VirtualPath.CreateAbsoluteAllowNull(path); } return WebConfigurationHost.OpenConfiguration(webLevel, fileMap, virtualPath, site, locationSubPath, server, userName, password, userToken); } // // API extra notes: // // OpenWebConfiguration(null) // - Open root web.config // // OpenWebConfiguration("/fxtest"); // - If calling from a hosted app (e.g. an ASP.NET page), it will open web.config at // virtual path "/fxtest" in the current running application (which gives the site) // - If calling from a non-hosted app (e.g. console app), it will do the same thing // except it will use the default web site. // // OpenWebConfiguration("/", "1", "fxtest") // - Open web.config at the root of site "1" and get the config that applies to location "fxtest" // // // OpenMachineConfiguration // public static Configuration OpenMachineConfiguration() { return OpenWebConfigurationImpl(WebLevel.Machine, null, null, null, null, null, null, null, IntPtr.Zero); } public static Configuration OpenMachineConfiguration(string locationSubPath) { return OpenWebConfigurationImpl(WebLevel.Machine, null, null, null, locationSubPath, null, null, null, IntPtr.Zero); } public static Configuration OpenMachineConfiguration(string locationSubPath, string server) { return OpenWebConfigurationImpl(WebLevel.Machine, null, null, null, locationSubPath, server, null, null, IntPtr.Zero); } public static Configuration OpenMachineConfiguration(string locationSubPath, string server, string userName, string password) { return OpenWebConfigurationImpl(WebLevel.Machine, null, null, null, locationSubPath, server, userName, password, IntPtr.Zero); } [SecurityPermission(SecurityAction.Demand, Unrestricted = true)] public static Configuration OpenMachineConfiguration(string locationSubPath, string server, IntPtr userToken) { return OpenWebConfigurationImpl(WebLevel.Machine, null, null, null, locationSubPath, server, null, null, userToken); } public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap) { return OpenWebConfigurationImpl(WebLevel.Machine, fileMap, null, null, null, null, null, null, IntPtr.Zero); } public static Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap, string locationSubPath) { return OpenWebConfigurationImpl(WebLevel.Machine, fileMap, null, null, locationSubPath, null, null, null, IntPtr.Zero); } // // OpenWebConfiguration // public static Configuration OpenWebConfiguration(string path) { return OpenWebConfigurationImpl(WebLevel.Path, null, path, null, null, null, null, null, IntPtr.Zero); } public static Configuration OpenWebConfiguration(string path, string site) { return OpenWebConfigurationImpl(WebLevel.Path, null, path, site, null, null, null, null, IntPtr.Zero); } public static Configuration OpenWebConfiguration(string path, string site, string locationSubPath) { return OpenWebConfigurationImpl(WebLevel.Path, null, path, site, locationSubPath, null, null, null, IntPtr.Zero); } public static Configuration OpenWebConfiguration(string path, string site, string locationSubPath, string server) { return OpenWebConfigurationImpl(WebLevel.Path, null, path, site, locationSubPath, server, null, null, IntPtr.Zero); } public static Configuration OpenWebConfiguration(string path, string site, string locationSubPath, string server, string userName, string password) { return OpenWebConfigurationImpl(WebLevel.Path, null, path, site, locationSubPath, server, userName, password, IntPtr.Zero); } [SecurityPermission(SecurityAction.Demand, Unrestricted = true)] public static Configuration OpenWebConfiguration(string path, string site, string locationSubPath, string server, IntPtr userToken) { return OpenWebConfigurationImpl(WebLevel.Path, null, path, site, locationSubPath, server, null, null, userToken); } public static Configuration OpenMappedWebConfiguration(WebConfigurationFileMap fileMap, string path) { return OpenWebConfigurationImpl(WebLevel.Path, fileMap, path, null, null, null, null, null, IntPtr.Zero); } public static Configuration OpenMappedWebConfiguration(WebConfigurationFileMap fileMap, string path, string site) { return OpenWebConfigurationImpl(WebLevel.Path, fileMap, path, site, null, null, null, null, IntPtr.Zero); } public static Configuration OpenMappedWebConfiguration(WebConfigurationFileMap fileMap, string path, string site, string locationSubPath) { return OpenWebConfigurationImpl(WebLevel.Path, fileMap, path, site, locationSubPath, null, null, null, IntPtr.Zero); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlBaseReader.cs
- Int32Storage.cs
- _NegoStream.cs
- SimpleLine.cs
- PageSettings.cs
- BaseComponentEditor.cs
- IMembershipProvider.cs
- SiteMapPath.cs
- RayMeshGeometry3DHitTestResult.cs
- XPathDocumentNavigator.cs
- OutputCacheSection.cs
- InternalControlCollection.cs
- UnmanagedMarshal.cs
- StylusPlugin.cs
- DialogResultConverter.cs
- XmlEncoding.cs
- PagesSection.cs
- Helpers.cs
- mansign.cs
- ActiveXContainer.cs
- ExpressionQuoter.cs
- BufferBuilder.cs
- TransformCryptoHandle.cs
- ControllableStoryboardAction.cs
- mediapermission.cs
- StrongTypingException.cs
- PassportAuthenticationModule.cs
- WhitespaceRuleReader.cs
- InstanceView.cs
- BridgeDataRecord.cs
- ExpressionBinding.cs
- SelectionItemProviderWrapper.cs
- DataSourceViewSchemaConverter.cs
- DoubleConverter.cs
- XmlAttributes.cs
- OperationPickerDialog.designer.cs
- DataGridPageChangedEventArgs.cs
- XamlTypeWithExplicitNamespace.cs
- HtmlToClrEventProxy.cs
- WindowsClientCredential.cs
- StrongNameKeyPair.cs
- EFTableProvider.cs
- ProxyHwnd.cs
- WindowsAltTab.cs
- ListItemParagraph.cs
- _Win32.cs
- StorageSetMapping.cs
- XmlAggregates.cs
- SupportingTokenAuthenticatorSpecification.cs
- EncryptedXml.cs
- MatrixConverter.cs
- InvariantComparer.cs
- OdbcPermission.cs
- CopyEncoder.cs
- ReadWriteSpinLock.cs
- AppDomainUnloadedException.cs
- GeneratedCodeAttribute.cs
- SqlUdtInfo.cs
- AutomationAttributeInfo.cs
- WebBrowserProgressChangedEventHandler.cs
- HtmlEmptyTagControlBuilder.cs
- ContainsSearchOperator.cs
- DesignTimeSiteMapProvider.cs
- CodeTypeMember.cs
- IImplicitResourceProvider.cs
- SystemIPInterfaceProperties.cs
- WorkflowInstanceUnhandledExceptionRecord.cs
- FileLoadException.cs
- UndoEngine.cs
- StrokeCollection.cs
- DataControlField.cs
- AsyncCompletedEventArgs.cs
- DbDataRecord.cs
- XmlDocumentFragment.cs
- MimePart.cs
- PeerNameRegistration.cs
- EventLog.cs
- ApplicationInfo.cs
- ZipIOBlockManager.cs
- RuleSettings.cs
- HttpBrowserCapabilitiesWrapper.cs
- XmlIncludeAttribute.cs
- UrlPath.cs
- CustomAssemblyResolver.cs
- WebEvents.cs
- X509CertificateInitiatorServiceCredential.cs
- DESCryptoServiceProvider.cs
- Journaling.cs
- NamespaceCollection.cs
- EmptyElement.cs
- StringSorter.cs
- HtmlTableRowCollection.cs
- ClockGroup.cs
- Expander.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- XmlCDATASection.cs
- BitmapEffectState.cs
- ExpandSegmentCollection.cs
- SafeLibraryHandle.cs
- EventListener.cs