Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / Configuration / CustomErrorsSection.cs / 2 / CustomErrorsSection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Configuration { using System; using System.Xml; using System.Configuration; using System.Collections.Specialized; using System.Collections; using System.IO; using System.Text; using System.Globalization; using System.Web.Util; using System.Web.Configuration; using System.Security.Permissions; /* From Machine.Config*/ [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class CustomErrorsSection : ConfigurationSection { private static ConfigurationPropertyCollection _properties; private static readonly ConfigurationProperty _propDefaultRedirect = new ConfigurationProperty("defaultRedirect", typeof(string), null, ConfigurationPropertyOptions.None); private static readonly ConfigurationProperty _propMode = new ConfigurationProperty("mode", typeof(CustomErrorsMode), CustomErrorsMode.RemoteOnly, ConfigurationPropertyOptions.None); private static readonly ConfigurationProperty _propErrors = new ConfigurationProperty(null, typeof(CustomErrorCollection), null, ConfigurationPropertyOptions.IsDefaultCollection); private string basepath = null; private string _DefaultAbsolutePath = null; private static CustomErrorsSection _default = null; static CustomErrorsSection() { // Property initialization _properties = new ConfigurationPropertyCollection(); _properties.Add(_propDefaultRedirect); _properties.Add(_propMode); _properties.Add(_propErrors); } public CustomErrorsSection() { } protected override ConfigurationPropertyCollection Properties { get { return _properties; } } [ConfigurationProperty("defaultRedirect")] public string DefaultRedirect { get { return (string)base[_propDefaultRedirect]; } set { base[_propDefaultRedirect] = value; } } [ConfigurationProperty("mode", DefaultValue = CustomErrorsMode.RemoteOnly)] public CustomErrorsMode Mode { get { return (CustomErrorsMode)base[_propMode]; } set { base[_propMode] = value; } } [ConfigurationProperty("", IsDefaultCollection = true)] public CustomErrorCollection Errors { get { return (CustomErrorCollection)base[_propErrors]; } } internal String DefaultAbsolutePath { get { if (_DefaultAbsolutePath == null) { _DefaultAbsolutePath = GetAbsoluteRedirect(DefaultRedirect, basepath); } return _DefaultAbsolutePath; } } internal String GetRedirectString(int code) { String r = null; if (Errors != null) { CustomError ce = Errors[(string)code.ToString(CultureInfo.InvariantCulture)]; if (ce != null) r = GetAbsoluteRedirect(ce.Redirect, basepath); } if (r == null) { r = DefaultAbsolutePath; } return r; } protected override void Reset(ConfigurationElement parentElement) { base.Reset(parentElement); CustomErrorsSection parent = parentElement as CustomErrorsSection; if (parent != null) { basepath = parent.basepath; } } protected override void DeserializeSection(XmlReader reader) { WebContext context; base.DeserializeSection(reader); // Determine Web Context context = EvaluationContext.HostingContext as WebContext; if (context != null) { basepath = UrlPath.AppendSlashToPathIfNeeded(context.Path); } } // // helper to create absolute redirect // internal static String GetAbsoluteRedirect(String path, String basePath) { if (path != null && UrlPath.IsRelativeUrl(path)) { if (String.IsNullOrEmpty(basePath)) basePath = "/"; path = UrlPath.Combine(basePath, path); } return path; } internal static CustomErrorsSection GetSettings(HttpContext context) { return GetSettings(context, false); } internal static CustomErrorsSection GetSettings(HttpContext context, bool canThrow) { CustomErrorsSection ce = null; RuntimeConfig runtimeConfig = null; if (canThrow) { runtimeConfig = RuntimeConfig.GetConfig(context); if (runtimeConfig != null) { ce = runtimeConfig.CustomErrors; } } else { runtimeConfig = RuntimeConfig.GetLKGConfig(context); if (runtimeConfig != null) { ce = runtimeConfig.CustomErrors; } if (ce == null) { if (_default == null) { _default = new CustomErrorsSection(); } ce = _default; } } return ce; } internal bool CustomErrorsEnabled(HttpRequest request) { // This could throw if the config file is malformed, but we don't want // to throw from here, as it would mess up error handling try { // Always turn of custom errors in retail deployment mode (DevDiv 36396) if (DeploymentSection.RetailInternal) return true; } catch { } switch (Mode) { case CustomErrorsMode.Off: return false; case CustomErrorsMode.On: return true; case CustomErrorsMode.RemoteOnly: return (!request.IsLocal); default: return false; } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ProjectionCamera.cs
- CompilerTypeWithParams.cs
- ResourceManagerWrapper.cs
- FlowDocumentReaderAutomationPeer.cs
- CapabilitiesSection.cs
- MetaColumn.cs
- LinqDataSourceStatusEventArgs.cs
- GuidelineCollection.cs
- PipelineModuleStepContainer.cs
- CompilerErrorCollection.cs
- XmlNotation.cs
- ReflectionTypeLoadException.cs
- FormsAuthenticationTicket.cs
- XXXOnTypeBuilderInstantiation.cs
- IItemContainerGenerator.cs
- Options.cs
- LogicalExpr.cs
- HttpValueCollection.cs
- DefaultDiscoveryServiceExtension.cs
- MetabaseServerConfig.cs
- SystemEvents.cs
- cache.cs
- SafeMemoryMappedViewHandle.cs
- MailAddress.cs
- ColorAnimationUsingKeyFrames.cs
- GeneralTransform.cs
- SafeNativeMethods.cs
- HttpContextBase.cs
- AppSettingsReader.cs
- util.cs
- Int32Rect.cs
- Attachment.cs
- PauseStoryboard.cs
- IISUnsafeMethods.cs
- ClipboardProcessor.cs
- TableItemPattern.cs
- DataGridViewBand.cs
- ClientRuntimeConfig.cs
- SqlBuilder.cs
- XPathNavigatorReader.cs
- WmlCommandAdapter.cs
- EditCommandColumn.cs
- SerializationInfo.cs
- XmlDigitalSignatureProcessor.cs
- DictationGrammar.cs
- MergeFilterQuery.cs
- ResourceBinder.cs
- NumberFormatInfo.cs
- Maps.cs
- ImportedNamespaceContextItem.cs
- WindowsScrollBarBits.cs
- TreeNodeCollectionEditor.cs
- IPEndPointCollection.cs
- HtmlButton.cs
- FileSystemEventArgs.cs
- MouseButtonEventArgs.cs
- FontEditor.cs
- ZoneLinkButton.cs
- Rectangle.cs
- CharEntityEncoderFallback.cs
- WebPartDisplayModeEventArgs.cs
- MultiView.cs
- MultilineStringConverter.cs
- HttpCookieCollection.cs
- TransactionInformation.cs
- VisualStyleTypesAndProperties.cs
- ReadContentAsBinaryHelper.cs
- TextTreeTextNode.cs
- CipherData.cs
- SafeNativeMethods.cs
- StringUtil.cs
- XmlLanguage.cs
- OrderedEnumerableRowCollection.cs
- DesignerVerbCollection.cs
- BaseResourcesBuildProvider.cs
- EntityCommandDefinition.cs
- CacheHelper.cs
- HTMLTextWriter.cs
- Ipv6Element.cs
- FileSystemEventArgs.cs
- ObjectListCommandCollection.cs
- OperationResponse.cs
- ClientUtils.cs
- FixedPageAutomationPeer.cs
- RectAnimationClockResource.cs
- AutoScrollExpandMessageFilter.cs
- CompositeFontParser.cs
- SequentialUshortCollection.cs
- QueryReaderSettings.cs
- BrushMappingModeValidation.cs
- sqlser.cs
- DataStreamFromComStream.cs
- XmlnsCache.cs
- LocalizableResourceBuilder.cs
- securestring.cs
- Visual3D.cs
- ToolStripManager.cs
- SpeechRecognitionEngine.cs
- WebPartHeaderCloseVerb.cs
- ResourceProviderFactory.cs