Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / Configuration / CustomErrorsSection.cs / 1 / 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 _propRedirectMode =
new ConfigurationProperty("redirectMode",
typeof(CustomErrorsRedirectMode),
CustomErrorsRedirectMode.ResponseRedirect,
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(_propRedirectMode);
_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("redirectMode", DefaultValue = CustomErrorsRedirectMode.ResponseRedirect)]
public CustomErrorsRedirectMode RedirectMode {
get {
return (CustomErrorsRedirectMode)base[_propRedirectMode];
}
set {
base[_propRedirectMode] = 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;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// 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 _propRedirectMode =
new ConfigurationProperty("redirectMode",
typeof(CustomErrorsRedirectMode),
CustomErrorsRedirectMode.ResponseRedirect,
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(_propRedirectMode);
_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("redirectMode", DefaultValue = CustomErrorsRedirectMode.ResponseRedirect)]
public CustomErrorsRedirectMode RedirectMode {
get {
return (CustomErrorsRedirectMode)base[_propRedirectMode];
}
set {
base[_propRedirectMode] = 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;
}
}
}
}
// 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
- Propagator.JoinPropagator.cs
- ContentElementAutomationPeer.cs
- BasePattern.cs
- XmlBinaryReader.cs
- GetParentChain.cs
- QueryResult.cs
- ProbeDuplex11AsyncResult.cs
- DataRowChangeEvent.cs
- AutoGeneratedField.cs
- UserControl.cs
- EmptyStringExpandableObjectConverter.cs
- ScriptResourceHandler.cs
- DotAtomReader.cs
- ImageDesigner.cs
- PerformanceCounter.cs
- UiaCoreApi.cs
- CodeVariableReferenceExpression.cs
- StringFreezingAttribute.cs
- TaiwanCalendar.cs
- SqlCharStream.cs
- SignatureToken.cs
- HttpPostedFile.cs
- SourceFileInfo.cs
- IPPacketInformation.cs
- DispatcherTimer.cs
- SqlTriggerAttribute.cs
- DeferredSelectedIndexReference.cs
- IsolationInterop.cs
- ResizeBehavior.cs
- ResXBuildProvider.cs
- NotifyParentPropertyAttribute.cs
- HiddenFieldPageStatePersister.cs
- JsonWriter.cs
- BindingExpression.cs
- SamlAuthorityBinding.cs
- FieldToken.cs
- Activator.cs
- DataException.cs
- OracleDataReader.cs
- BindStream.cs
- EditBehavior.cs
- UnlockInstanceAsyncResult.cs
- EntityWithChangeTrackerStrategy.cs
- SharedUtils.cs
- WinFormsSecurity.cs
- CodeMethodInvokeExpression.cs
- PageCodeDomTreeGenerator.cs
- FontFamilyValueSerializer.cs
- EventManager.cs
- ProxyWebPart.cs
- SamlConstants.cs
- MsmqActivation.cs
- TargetFrameworkUtil.cs
- ToolStripContainer.cs
- XmlAnyElementAttribute.cs
- FileDialogPermission.cs
- SaveFileDialog.cs
- AttachmentCollection.cs
- WindowsEditBox.cs
- WebPartMenuStyle.cs
- Compiler.cs
- DefaultBinder.cs
- ApplicationProxyInternal.cs
- DispatchWrapper.cs
- RunClient.cs
- DEREncoding.cs
- Common.cs
- PrintDialogException.cs
- ContravarianceAdapter.cs
- Transform3DGroup.cs
- ScriptMethodAttribute.cs
- MessageQueuePermissionAttribute.cs
- DBDataPermission.cs
- AssociatedControlConverter.cs
- httpserverutility.cs
- Geometry3D.cs
- IndexedGlyphRun.cs
- RedBlackList.cs
- VarRemapper.cs
- DisplayNameAttribute.cs
- InvokeBinder.cs
- EntityDataSourceChangedEventArgs.cs
- XamlTreeBuilderBamlRecordWriter.cs
- ConfigurationElementProperty.cs
- SspiWrapper.cs
- PasswordBoxAutomationPeer.cs
- Helper.cs
- PresentationSource.cs
- TogglePatternIdentifiers.cs
- SchemaSetCompiler.cs
- RefreshEventArgs.cs
- ResXBuildProvider.cs
- PaperSource.cs
- BufferBuilder.cs
- ObjectDataSourceEventArgs.cs
- DocumentPaginator.cs
- BindUriHelper.cs
- DictionaryContent.cs
- TextContainer.cs
- NativeWindow.cs