diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-06-10 18:12:31 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-06-10 18:12:31 -0700 |
commit | 4aa2ffd3206cd342282e6bf3e0a518a6d0f65529 (patch) | |
tree | 149114a89f4eeea76c9e1f5a0e2e0ef4f5c6d36d /src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs | |
parent | f70166165c385afa52393bbe384f65c100ef94e5 (diff) | |
parent | 9ba6f876e55dfb12126081c57ae146cbe09ede53 (diff) | |
download | DotNetOpenAuth-4aa2ffd3206cd342282e6bf3e0a518a6d0f65529.zip DotNetOpenAuth-4aa2ffd3206cd342282e6bf3e0a518a6d0f65529.tar.gz DotNetOpenAuth-4aa2ffd3206cd342282e6bf3e0a518a6d0f65529.tar.bz2 |
Merge branch 'v4.0'
Conflicts:
projecttemplates/projecttemplates.proj
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs')
-rw-r--r-- | src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs b/src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs index f5c8547..eb2020b 100644 --- a/src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs +++ b/src/DotNetOpenAuth.AspNet/MachineKeyUtil.cs @@ -10,8 +10,10 @@ namespace DotNetOpenAuth.AspNet { using System.Diagnostics.CodeAnalysis; using System.IO; using System.Net; + using System.Reflection; using System.Security.Cryptography; using System.Text; + using System.Web; using System.Web.Security; /// <summary> @@ -84,12 +86,20 @@ namespace DotNetOpenAuth.AspNet { /// </summary> /// <returns>The machine key implementation</returns> private static IMachineKey GetMachineKeyImpl() { - 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); + // 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 (protectThunk != null && unprotectThunk != null) - ? (IMachineKey)new MachineKey45(protectThunk, unprotectThunk) // ASP.NET 4.5 - : (IMachineKey)new MachineKey40(); // ASP.NET 4.0 + return new MachineKey40(); // ASP.NET 4.0 } /// <summary> |