Ejemplo n.º 1
0
        /// <summary>
        /// Gets the machine key implementation based on the runtime framework version.
        /// </summary>
        /// <returns>The machine key implementation</returns>
        private static IMachineKey GetMachineKeyImpl()
        {
            // Late bind to the MachineKey.Protect / Unprotect methods only if <httpRuntime targetFramework="4.5" />.
            // This helps ensure that round-tripping the payloads continues to work even if the application is
            // deployed to a mixed 4.0 / 4.5 farm environment.
            PropertyInfo targetFrameworkProperty = typeof(HttpRuntime).GetProperty("TargetFramework", typeof(Version));
            Version      targetFramework         = (targetFrameworkProperty != null) ? targetFrameworkProperty.GetValue(null, null) as Version : null;

            if (targetFramework != null && targetFramework >= new Version(4, 5))
            {
                ProtectUnprotect protectThunk   = (ProtectUnprotect)Delegate.CreateDelegate(typeof(ProtectUnprotect), typeof(MachineKey), "Protect", ignoreCase: false, throwOnBindFailure: false);
                ProtectUnprotect unprotectThunk = (ProtectUnprotect)Delegate.CreateDelegate(typeof(ProtectUnprotect), typeof(MachineKey), "Unprotect", ignoreCase: false, throwOnBindFailure: false);
                if (protectThunk != null && unprotectThunk != null)
                {
                    return(new MachineKey45(protectThunk, unprotectThunk));                    // ASP.NET 4.5
                }
            }

            return(new MachineKey40());            // ASP.NET 4.0
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MachineKey45"/> class.
 /// </summary>
 /// <param name="protectThunk">The protect thunk.</param>
 /// <param name="unprotectThunk">The unprotect thunk.</param>
 public MachineKey45(ProtectUnprotect protectThunk, ProtectUnprotect unprotectThunk)
 {
     this.protectThunk   = protectThunk;
     this.unprotectThunk = unprotectThunk;
 }
			/// <summary>
			/// Initializes a new instance of the <see cref="MachineKey45"/> class.
			/// </summary>
			/// <param name="protectThunk">The protect thunk.</param>
			/// <param name="unprotectThunk">The unprotect thunk.</param>
			public MachineKey45(ProtectUnprotect protectThunk, ProtectUnprotect unprotectThunk) {
				this.protectThunk = protectThunk;
				this.unprotectThunk = unprotectThunk;
			}