1 //------------------------------------------------------------------------------
2 // <copyright file="DynamicValidationShim.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 // This is a special class used by Microsoft.Web.Infrastructure.dll to interface with the request validation system.
8 // M.W.I was created before the existence of this class and has its own implementation of granular request validation,
9 // but it uses reflection to look for this class. If this class exists, M.W.I calls the methods defined on this class
10 // rather than using its own internal implementation.
12 namespace Microsoft.Web.Infrastructure.DynamicValidationHelper {
14 using System.Collections.Specialized;
17 internal static class DynamicValidationShim {
19 // Enables granular request validation for the current request.
20 internal static void EnableDynamicValidation(HttpContext context) {
21 // Because .NET 4.5 is an in-place update granular request validation is disabled by default for back-compat
22 // reasons (request validation defaults to the 4.0 behavior).
23 // We need to enable it for the current request so that MVC 3 and Web Pages 1 continue to work on .NET 4.5.
24 context.Request.EnableGranularRequestValidation();
27 // Returns a value indicating whether request validation was ever turned on for this request.
28 internal static bool IsValidationEnabled(HttpContext context) {
29 return context.Request.ValidateInputWasCalled;
32 // Given an HttpContext object, provides access to the unvalidated Form and QueryString collections.
33 internal static void GetUnvalidatedCollections(HttpContext context, out Func<NameValueCollection> formGetter, out Func<NameValueCollection> queryStringGetter) {
34 UnvalidatedRequestValues unvalidated = context.Request.Unvalidated;
35 formGetter = () => unvalidated.Form;
36 queryStringGetter = () => unvalidated.QueryString;