Add a discriminator so that DataProtection doesn't use the same subkey across apps by default.

This commit is contained in:
Levi B 2014-10-10 15:00:09 -07:00
parent c859c3dad5
commit ebe4948a3e
1 changed files with 9 additions and 0 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Security.DataProtection;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
@ -46,6 +47,14 @@ namespace Microsoft.AspNet.Hosting
var serviceCollection = new ServiceCollection();
serviceCollection.Add(HostingServices.GetDefaultServices(config));
serviceCollection.AddInstance<IHostingEnvironment>(hostingEnv);
// The application name is a "good enough" mechanism to identify this application
// on the machine and to prevent subkeys from being shared across multiple applications
// by default.
serviceCollection.ConfigureOptions<DataProtectionOptions>(options =>
{
options.ApplicationDiscriminator = appEnv.ApplicationName;
});
var services = serviceCollection.BuildServiceProvider(_serviceProvider);
var context = new HostingContext()