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
- OutOfProcStateClientManager.cs
- _RequestCacheProtocol.cs
- IncrementalReadDecoders.cs
- WebRequest.cs
- PathNode.cs
- DataGridCommandEventArgs.cs
- InstalledFontCollection.cs
- CollectionView.cs
- ConfigurationManagerHelper.cs
- ServerValidateEventArgs.cs
- FirstMatchCodeGroup.cs
- PersonalizationDictionary.cs
- StylusLogic.cs
- UnionCodeGroup.cs
- Bezier.cs
- TypeDescriptionProvider.cs
- ThicknessAnimation.cs
- StorageScalarPropertyMapping.cs
- ReadOnlyCollection.cs
- EventWaitHandle.cs
- PromptEventArgs.cs
- IISUnsafeMethods.cs
- TemplateBindingExpressionConverter.cs
- ExpressionNode.cs
- TreeViewBindingsEditorForm.cs
- XmlSchemaCollection.cs
- TableLayoutPanelDesigner.cs
- WindowsToolbar.cs
- DictionaryCustomTypeDescriptor.cs
- CollectionDataContractAttribute.cs
- EdmError.cs
- ReadOnlyTernaryTree.cs
- TrimSurroundingWhitespaceAttribute.cs
- SystemIcons.cs
- AnnotationMap.cs
- COMException.cs
- TextTreeObjectNode.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- LocalizabilityAttribute.cs
- ToolTipAutomationPeer.cs
- ObjectAnimationBase.cs
- SqlPersistenceWorkflowInstanceDescription.cs
- MiniLockedBorderGlyph.cs
- MenuBase.cs
- ReachSerializableProperties.cs
- CompensationTokenData.cs
- CFGGrammar.cs
- ControlUtil.cs
- PlanCompilerUtil.cs
- glyphs.cs
- ExportException.cs
- PixelFormat.cs
- AssemblyAttributesGoHere.cs
- XmlSubtreeReader.cs
- CancelAsyncOperationRequest.cs
- UriTemplateCompoundPathSegment.cs
- SubqueryRules.cs
- DrawingContextDrawingContextWalker.cs
- IgnoreDeviceFilterElement.cs
- AQNBuilder.cs
- HashSetDebugView.cs
- FlowDocumentScrollViewer.cs
- RadialGradientBrush.cs
- DataGridColumnStyleMappingNameEditor.cs
- PointHitTestParameters.cs
- FixedDocumentSequencePaginator.cs
- RemoteHelper.cs
- TypeDescriptionProvider.cs
- SecurityContextCookieSerializer.cs
- StateDesigner.CommentLayoutGlyph.cs
- NameValueCollection.cs
- FixedSOMPageElement.cs
- CollectionChangedEventManager.cs
- RSAPKCS1SignatureFormatter.cs
- EventBindingService.cs
- PriorityQueue.cs
- CacheSection.cs
- FontFamilyIdentifier.cs
- OrderByLifter.cs
- ListBindableAttribute.cs
- BevelBitmapEffect.cs
- AuthorizationRule.cs
- FormParameter.cs
- GenericArgumentsUpdater.cs
- RsaSecurityToken.cs
- FlowDocumentPageViewerAutomationPeer.cs
- DependentList.cs
- ControlOperationBehavior.cs
- ManualResetEvent.cs
- MeshGeometry3D.cs
- WindowsFont.cs
- WSFederationHttpSecurityElement.cs
- TextEditorDragDrop.cs
- TypedDataSourceCodeGenerator.cs
- Merger.cs
- RightsManagementEncryptionTransform.cs
- PaperSize.cs
- HashCodeCombiner.cs
- DataGridColumnReorderingEventArgs.cs
- DataTable.cs