Merge pull request #3373 from marek-safar/net-4.6.2
[mono.git] / mcs / class / referencesource / System.Web / DynamicValidationShim.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="DynamicValidationShim.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
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.
11
12 namespace Microsoft.Web.Infrastructure.DynamicValidationHelper {
13     using System;
14     using System.Collections.Specialized;
15     using System.Web;
16
17     internal static class DynamicValidationShim {
18
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();
25         }
26
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;
30         }
31
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;
37         }
38
39     }
40 }