Added DPAPI implementation that works on mono

This commit is contained in:
David Fowler 2014-04-29 23:58:53 -07:00
parent 4077c03a7b
commit 7b4e1fd48e
3 changed files with 32 additions and 5 deletions

View File

@ -37,11 +37,20 @@ namespace Microsoft.AspNet.Hosting
Lifecycle = LifecycleKind.Scoped
};
// The default IDataProtectionProvider is a singleton.
// Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI
// is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to
// replace this service as part of application initialization.
yield return describer.Instance<IDataProtectionProvider>(DataProtectionProvider.CreateFromDpapi());
if (PlatformHelper.IsMono)
{
#if NET45
yield return describer.Instance<IDataProtectionProvider>(DataProtectionProvider.CreateFromLegacyDpapi());
#endif
}
else
{
// The default IDataProtectionProvider is a singleton.
// Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI
// is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to
// replace this service as part of application initialization.
yield return describer.Instance<IDataProtectionProvider>(DataProtectionProvider.CreateFromDpapi());
}
}
}
}

View File

@ -29,6 +29,7 @@
<Compile Include="HostingServices.cs" />
<Compile Include="IHostingEngine.cs" />
<Compile Include="PipelineInstance.cs" />
<Compile Include="PlatformHelper.cs" />
<Compile Include="Program.cs" />
<Compile Include="Server\IServerFactory.cs" />
<Compile Include="Server\IServerManager.cs" />

View File

@ -0,0 +1,17 @@
using System;
namespace Microsoft.AspNet.Hosting
{
internal static class PlatformHelper
{
private static Lazy<bool> _isMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null);
public static bool IsMono
{
get
{
return _isMono.Value;
}
}
}
}