Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / RequestValidator.cs / 1305376 / RequestValidator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Base class providing extensibility hooks for custom request validation * * Copyright (c) 2009 Microsoft Corporation */ namespace System.Web.Util { using System; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Web; using System.Web.Configuration; public class RequestValidator { private static RequestValidator _customValidator; private static readonly Lazy_customValidatorResolver = new Lazy (GetCustomValidatorFromConfig); public static RequestValidator Current { get { if (_customValidator == null) { _customValidator = _customValidatorResolver.Value; } return _customValidator; } set { if (value == null) { throw new ArgumentNullException("value"); } _customValidator = value; } } private static RequestValidator GetCustomValidatorFromConfig() { // App since this is static per AppDomain RuntimeConfig config = RuntimeConfig.GetAppConfig(); HttpRuntimeSection runtimeSection = config.HttpRuntime; string validatorTypeName = runtimeSection.RequestValidationType; // validate the type Type validatorType = ConfigUtil.GetType(validatorTypeName, "requestValidationType", runtimeSection); ConfigUtil.CheckBaseType(typeof(RequestValidator) /* expectedBaseType */, validatorType, "requestValidationType", runtimeSection); // instantiate RequestValidator validator = (RequestValidator)HttpRuntime.CreatePublicInstance(validatorType); return validator; } internal static void InitializeOnFirstRequest() { // instantiate the validator if it hasn't already been created RequestValidator validator = _customValidatorResolver.Value; } private static bool IsAtoZ(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", Justification = "This is an appropriate way to return multiple pieces of data.")] protected internal virtual bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex) { if (requestValidationSource == RequestValidationSource.Headers) { validationFailureIndex = 0; return true; // Ignore Headers collection in the default implementation } return !CrossSiteScriptingValidation.IsDangerousString(value, out validationFailureIndex); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Base class providing extensibility hooks for custom request validation * * Copyright (c) 2009 Microsoft Corporation */ namespace System.Web.Util { using System; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Web; using System.Web.Configuration; public class RequestValidator { private static RequestValidator _customValidator; private static readonly Lazy_customValidatorResolver = new Lazy (GetCustomValidatorFromConfig); public static RequestValidator Current { get { if (_customValidator == null) { _customValidator = _customValidatorResolver.Value; } return _customValidator; } set { if (value == null) { throw new ArgumentNullException("value"); } _customValidator = value; } } private static RequestValidator GetCustomValidatorFromConfig() { // App since this is static per AppDomain RuntimeConfig config = RuntimeConfig.GetAppConfig(); HttpRuntimeSection runtimeSection = config.HttpRuntime; string validatorTypeName = runtimeSection.RequestValidationType; // validate the type Type validatorType = ConfigUtil.GetType(validatorTypeName, "requestValidationType", runtimeSection); ConfigUtil.CheckBaseType(typeof(RequestValidator) /* expectedBaseType */, validatorType, "requestValidationType", runtimeSection); // instantiate RequestValidator validator = (RequestValidator)HttpRuntime.CreatePublicInstance(validatorType); return validator; } internal static void InitializeOnFirstRequest() { // instantiate the validator if it hasn't already been created RequestValidator validator = _customValidatorResolver.Value; } private static bool IsAtoZ(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", Justification = "This is an appropriate way to return multiple pieces of data.")] protected internal virtual bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex) { if (requestValidationSource == RequestValidationSource.Headers) { validationFailureIndex = 0; return true; // Ignore Headers collection in the default implementation } return !CrossSiteScriptingValidation.IsDangerousString(value, out validationFailureIndex); } } } // 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
- TemplateFactory.cs
- DataGridViewRowStateChangedEventArgs.cs
- MetadataProperty.cs
- ContractMapping.cs
- DirectoryInfo.cs
- DispatcherTimer.cs
- DataGridViewRowStateChangedEventArgs.cs
- DbProviderFactory.cs
- DynamicValueConverter.cs
- MimePart.cs
- Zone.cs
- SmiEventSink.cs
- SqlEnums.cs
- OrderedDictionary.cs
- SortKey.cs
- ProcessRequestArgs.cs
- HttpResponse.cs
- VersionedStream.cs
- SafeLocalMemHandle.cs
- ConfigUtil.cs
- TextPattern.cs
- MobileTextWriter.cs
- AutomationPropertyInfo.cs
- RegularExpressionValidator.cs
- SerializableAttribute.cs
- BitmapEffectCollection.cs
- CallSiteOps.cs
- OracleParameterBinding.cs
- HealthMonitoringSection.cs
- PropertyFilterAttribute.cs
- IgnoreDataMemberAttribute.cs
- AsyncPostBackTrigger.cs
- IfJoinedCondition.cs
- PropertyCondition.cs
- CngAlgorithm.cs
- HtmlShim.cs
- DataServiceRequest.cs
- PrintDialogDesigner.cs
- Codec.cs
- PersonalizationProvider.cs
- ToolboxItemAttribute.cs
- ParseElementCollection.cs
- ExceptionAggregator.cs
- CodeDOMProvider.cs
- TextEditorCharacters.cs
- RegexRunner.cs
- MaskedTextBox.cs
- ComponentChangedEvent.cs
- XmlValidatingReaderImpl.cs
- TraceSwitch.cs
- EditableTreeList.cs
- Content.cs
- MultiAsyncResult.cs
- IPPacketInformation.cs
- ReferenceEqualityComparer.cs
- SupportingTokenDuplexChannel.cs
- ObjectNotFoundException.cs
- Context.cs
- DesignerListAdapter.cs
- RedirectionProxy.cs
- HatchBrush.cs
- SynchronizedRandom.cs
- ReflectEventDescriptor.cs
- ImageMetadata.cs
- Page.cs
- AppDomainInfo.cs
- PropertyDescriptor.cs
- CqlParser.cs
- BitStack.cs
- UnsafeNativeMethods.cs
- DocumentViewerHelper.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- RotateTransform3D.cs
- XPathSelfQuery.cs
- ServiceOperationWrapper.cs
- TrackBarRenderer.cs
- EmptyArray.cs
- FeatureManager.cs
- BitmapFrame.cs
- ParseNumbers.cs
- MenuCommandsChangedEventArgs.cs
- InputLangChangeEvent.cs
- BaseTemplateBuildProvider.cs
- OnOperation.cs
- SchemaName.cs
- CacheModeConverter.cs
- TypeRefElement.cs
- GenericUriParser.cs
- Timer.cs
- Configuration.cs
- COM2ColorConverter.cs
- RightsManagementPermission.cs
- LineInfo.cs
- Utilities.cs
- PreviewPrintController.cs
- DocumentGridContextMenu.cs
- ReachPrintTicketSerializer.cs
- HtmlEncodedRawTextWriter.cs
- TlsnegoTokenProvider.cs
- RouteItem.cs