예제 #1
0
        public static IDataProtectionBuilder UseAzureWebsitesProviderSettings(this IDataProtectionBuilder builder, bool skipEnvironmentValidation = false)
        {
            if (skipEnvironmentValidation || Util.IsAzureEnvironment())
            {
                builder.DisableAutomaticKeyGeneration();
                builder.SetDefaultKeyLifetime(TimeSpan.MaxValue);
                builder.Services.AddSingleton <IXmlRepository, AzureWebsitesXmlRepository>();
            }

            return(builder);
        }
예제 #2
0
        public static void AddWebAppOptions(this IServiceCollection ext, WebApplicationOptions options = null)
        {
            ext     = ext ?? throw new ArgumentNullException(nameof(ext));
            options = options ?? new WebApplicationOptions();

            ext.ConfigureApplicationCookie(opt => {
                opt.Cookie.Name = options.ApplicationCookieName ?? (options.CookieBaseName != null ? $"{options.CookieBaseName}_app" : opt.Cookie.Name);
            });
            ext.ConfigureExternalCookie(opt => {
                opt.Cookie.Name = options.ExternalCookieName ?? (options.CookieBaseName != null ? $"{options.CookieBaseName}_ext" : opt.Cookie.Name);
            });

            IDataProtectionBuilder dpBuilder = ext.AddDataProtection()
                                               .SetApplicationName(options.DataProtection.ApplicationName)
                                               .PersistKeysToFileSystem(new DirectoryInfo(options.DataProtection.KeyRingPath));

            if (options.DataProtection.DisableAutomaticKeyGeneration)
            {
                dpBuilder.DisableAutomaticKeyGeneration();
            }
        }