File: DynamicValidationShim.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (40 lines) | stat: -rw-r--r-- 2,254 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//------------------------------------------------------------------------------
// <copyright file="DynamicValidationShim.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

// This is a special class used by Microsoft.Web.Infrastructure.dll to interface with the request validation system.
// M.W.I was created before the existence of this class and has its own implementation of granular request validation,
// but it uses reflection to look for this class. If this class exists, M.W.I calls the methods defined on this class
// rather than using its own internal implementation.

namespace Microsoft.Web.Infrastructure.DynamicValidationHelper {
    using System;
    using System.Collections.Specialized;
    using System.Web;

    internal static class DynamicValidationShim {

        // Enables granular request validation for the current request.
        internal static void EnableDynamicValidation(HttpContext context) {
            // Because .NET 4.5 is an in-place update granular request validation is disabled by default for back-compat
            // reasons (request validation defaults to the 4.0 behavior).
            // We need to enable it for the current request so that MVC 3 and Web Pages 1 continue to work on .NET 4.5.
            context.Request.EnableGranularRequestValidation();
        }

        // Returns a value indicating whether request validation was ever turned on for this request.
        internal static bool IsValidationEnabled(HttpContext context) {
            return context.Request.ValidateInputWasCalled;
        }

        // Given an HttpContext object, provides access to the unvalidated Form and QueryString collections.
        internal static void GetUnvalidatedCollections(HttpContext context, out Func<NameValueCollection> formGetter, out Func<NameValueCollection> queryStringGetter) {
            UnvalidatedRequestValues unvalidated = context.Request.Unvalidated;
            formGetter = () => unvalidated.Form;
            queryStringGetter = () => unvalidated.QueryString;
        }

    }
}