当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.AddDataProtection方法代码示例

本文整理汇总了C#中IServiceCollection.AddDataProtection方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddDataProtection方法的具体用法?C# IServiceCollection.AddDataProtection怎么用?C# IServiceCollection.AddDataProtection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceCollection的用法示例。


在下文中一共展示了IServiceCollection.AddDataProtection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDataProtection();
     services.Configure<ExternalAuthenticationOptions>(options =>
     {
         options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
     });
 }
开发者ID:SacmaIslerOfisi,项目名称:Security,代码行数:8,代码来源:Startup.cs

示例2: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // DI bindings
            new DependencyInjection().Bind(services);

            services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
            services.AddDataProtection();
            services.AddMvc();
        }
开发者ID:marcelo-mason,项目名称:Angular-WebAPI-Boilerplate,代码行数:9,代码来源:Startup.cs

示例3: ConfigureServices

        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection();

            services.AddMvc();

            // I only put this here to keep things simple for people :)
            services.AddWebApiConventions();
        }
开发者ID:cmichaelgraham,项目名称:Aurelia-Demo,代码行数:10,代码来源:Startup.cs

示例4: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // never persist key store to local directory, just for demo purposes
            services.AddDataProtection()
                .SetApplicationName("DataProtectionDemo")
                .PersistKeysToFileSystem(new DirectoryInfo(_env.ContentRootPath));
                //.ProtectKeysWithDpapi();
        }
开发者ID:ReinhardHsu,项目名称:AspNetCoreSecuritySamples,代码行数:10,代码来源:Startup.cs

示例5: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection();

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<OperationalContext>(o => o.UseSqlServer(Configuration["IdSvr3:ConnString:Identity_Operational"]))
                .AddDbContext<ClientConfigurationContext>(o => o.UseSqlServer(Configuration["IdSvr3:ConnString:Identity_Client"]))
                .AddDbContext<ScopeConfigurationContext>(o => o.UseSqlServer(Configuration["IdSvr3:ConnString:Identity_Scopes"]));
        }
开发者ID:Junicus,项目名称:Sample2020,代码行数:11,代码来源:Startup.cs

示例6: AddViewServices

        // Internal for testing.
        internal static void AddViewServices(IServiceCollection services)
        {
            services.AddDataProtection();
            services.AddAntiforgery();
            services.AddWebEncoders();

            services.TryAddEnumerable(
                ServiceDescriptor.Transient<IConfigureOptions<MvcViewOptions>, MvcViewOptionsSetup>());

            //
            // View Engine and related infrastructure
            //
            // The provider is inexpensive to initialize and provides ViewEngines that may require request
            // specific services.
            services.TryAddScoped<ICompositeViewEngine, CompositeViewEngine>();

            // Support for activating ViewDataDictionary
            services.TryAddEnumerable(
                ServiceDescriptor
                    .Transient<IControllerPropertyActivator, ViewDataDictionaryControllerPropertyActivator>());

            //
            // HTML Helper
            //
            services.TryAddTransient<IHtmlHelper, HtmlHelper>();
            services.TryAddTransient(typeof(IHtmlHelper<>), typeof(HtmlHelper<>));

            // DefaultHtmlGenerator is pretty much stateless but depends on IUrlHelper, which is scoped.
            // Therefore it too is scoped.
            services.TryAddScoped<IHtmlGenerator, DefaultHtmlGenerator>();

            //
            // JSON Helper
            //
            services.TryAddSingleton<IJsonHelper, JsonHelper>();
            services.TryAdd(ServiceDescriptor.Singleton<JsonOutputFormatter>(serviceProvider =>
            {
                var options = serviceProvider.GetRequiredService<IOptions<MvcJsonOptions>>().Options;
                return new JsonOutputFormatter(options.SerializerSettings);
            }));

            //
            // View Components
            //
            // These do caching so they should stay singleton
            services.TryAddSingleton<IViewComponentSelector, DefaultViewComponentSelector>();
            services.TryAddSingleton<IViewComponentActivator, DefaultViewComponentActivator>();
            services.TryAddSingleton<
                IViewComponentDescriptorCollectionProvider,
                DefaultViewComponentDescriptorCollectionProvider>();

            services.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>();
            services.TryAddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
            services.TryAddTransient<IViewComponentHelper, DefaultViewComponentHelper>();
        }
开发者ID:notami18,项目名称:Mvc,代码行数:56,代码来源:MvcViewFeaturesMvcBuilderExtensions.cs

示例7: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            OnConfigureServices(services);

            services.AddDataProtection();

            services.AddIdentityServer(Options)
                .AddInMemoryClients(Clients)
                .AddInMemoryScopes(Scopes)
                .AddInMemoryUsers(Users);
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:11,代码来源:IdentityServerPipeline.cs

示例8: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection();

            services.AddScoped<IUserProfileRepository, UserProfileRepository>();

            // Configure SQL connection string
            services.AddEntityFramework().AddSqlServer().AddDbContext<TeammateOnlineContext>(options =>
            {
                options.UseSqlServer(Configuration.GetSection("Database:ConnectionString").Value);
            });
        }
开发者ID:thors1982,项目名称:TeammateOnlineIdentity,代码行数:14,代码来源:Startup.cs

示例9: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddTransient<IConfigurationRepository>(p => new FileConfigurationRepository("files", p.GetService<ILogger<FileConfigurationRepository>>()));

            services.AddLogging();

            services.AddDataProtection();

            services.AddTransient<IAuthenticationService, AuthenticationService>();
            services.AddTransient<IKeyGeneratorService, AuthenticationService>();
        }
开发者ID:sebug,项目名称:ConfigurationService,代码行数:15,代码来源:Startup.cs

示例10: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection();

            //Set up CORS
            var policy = new CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));
        }
开发者ID:tadmcclellan,项目名称:WebAPI,代码行数:16,代码来源:Startup.cs

示例11: ConfigureProductionServices

        public void ConfigureProductionServices(IServiceCollection services)
        {
            ConfigureServices(services);

            // register redis connection
            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("redis"));
            services.AddSingleton(redis);

            // register dataprotector
            services.AddDataProtection(options =>
            {
                options.ApplicationDiscriminator = "dgo";
            });
        }
开发者ID:HopeNB,项目名称:web,代码行数:14,代码来源:Startup.cs

示例12: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            OnConfigureServices(services);

            services.AddDataProtection();

            Options.SigningCertificate = new X509Certificate2(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "idsrvtest.pfx"), "idsrv3test");

            services.AddIdentityServer(Options)
                .AddInMemoryClients(Clients)
                .AddInMemoryScopes(Scopes)
                .AddInMemoryUsers(Users);
        }
开发者ID:RajMondaz,项目名称:IdentityServer4,代码行数:15,代码来源:IdentityServerPipeline.cs

示例13: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration["Production:SqliteConnectionString"];

            services.AddEntityFramework()
                .AddSqlite()
                .AddDbContext<MyIdentityDbContext>(options => options.UseSqlite(connection));

            services.AddIdentity<MyUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit = false;
                options.Password.RequireLowercase = false;
                options.Password.RequireNonLetterOrDigit = false;
                options.Password.RequireUppercase = false;
                options.Password.RequiredLength = 6;
            })
                .AddEntityFrameworkStores<MyIdentityDbContext>()
                .AddDefaultTokenProviders();

            services.AddDataProtection();
        }
开发者ID:firehang,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:21,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // *** CHANGE THIS FOR PRODUCTION USE ***
            // Here, we're generating a random key to sign tokens - obviously this means
            // that each time the app is started the key will change, and multiple servers 
            // all have different keys. This should be changed to load a key from a file 
            // securely delivered to your application, controlled by configuration.
            //
            // See the RSAKeyUtils.GetKeyParameters method for an examle of loading from
            // a JSON file.
            //RSAParameters keyParams = RSAKeyUtils.GetRandomKey();

            services.AddDataProtection();
            services.ConfigureDataProtection(configure =>
            {
              // persist keys to a specific directory
              configure.PersistKeysToFileSystem(new DirectoryInfo(@".\keys"));
              // uncomment when doing this from different application
              //configure.SetApplicationName("SameAppName"); 
            });
            var lServices = services.BuildServiceProvider();

            tokenOptions = RSAKeyUtils.GetTokenOptions(lServices);
            
            // Save the token options into an instance so they're accessible to the 
            // controller.
            services.AddInstance<TokenAuthOptions>(tokenOptions);

            // Enable the use of an [Authorize("Bearer")] attribute on methods and classes to protect.
            services.AddAuthorization(auth =>
            {
                auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
                    .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme‌​)
                    .RequireAuthenticatedUser().Build());
            });

            services.AddMvc();
        }
开发者ID:geertendoornenbal,项目名称:ASPNETSelfCreatedTokenAuthExample,代码行数:38,代码来源:Startup.cs

示例15: ConfigureServices

        // This method gets called by the runtime.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddWebEncoders();
            services.AddDataProtection();

            services.Configure<Auth0Settings>(Configuration.GetSection("Auth0"));
            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure<SharedAuthenticationOptions>(options =>
            {
                options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            });

            var settings = Configuration.Get<Auth0Settings>("Auth0");
            services.UseAuth0(settings.Domain, settings.ClientId, settings.ClientSecret, settings.RedirectUri, notification =>
            {
                var identity = notification.AuthenticationTicket.Principal.Identity as ClaimsIdentity;

                // Optional: add custom claims.
                /* 
                if (identity.HasClaim(c => c.Type == "name"))
                    identity.AddClaim(new Claim(ClaimTypes.Name, identity.FindFirst("name").Value));
                identity.AddClaim(new Claim("tenant", "12345"));
                identity.AddClaim(new Claim("custom-claim", "custom-value"));
                */

                // Optional: store tokens in the user object so you can retrieve those later.
                /*
                if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.AccessToken))
                    identity.AddClaim(new Claim("access_token", notification.TokenEndpointResponse.AccessToken));
                if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.IdToken))
                    identity.AddClaim(new Claim("id_token", notification.TokenEndpointResponse.IdToken));
                if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.RefreshToken))
                    identity.AddClaim(new Claim("refresh_token", notification.TokenEndpointResponse.RefreshToken)); 
                */
                return Task.FromResult(true);
            });
        }
开发者ID:JimGeersinga,项目名称:auth0-aspnet5,代码行数:39,代码来源:Startup.cs


注:本文中的IServiceCollection.AddDataProtection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。