本文整理汇总了C#中IServiceCollection.AddIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddIdentity方法的具体用法?C# IServiceCollection.AddIdentity怎么用?C# IServiceCollection.AddIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddIdentity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
if (Configuration["Data:UseSqLite"] == "true")
{
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration["Data:DefaultConnection:SqLiteConnectionString"]));
}
else
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:MsSqlConnectionString"]));
}
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
//Password policy
//stackoverflow.com/questions/27831597/how-do-i-define-the-password-rules-for-identity-in-asp-net-5-mvc-6-vnext
services.AddIdentity<ApplicationUser, IdentityRole>(o => {
// configure identity options
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonLetterOrDigit = false; ;
o.Password.RequiredLength = 6;
}).AddDefaultTokenProviders();
}
示例2: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddIdentity<ApplicationUser, IdentityRole>(o => {
// configure identity options
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonLetterOrDigit = false; ;
o.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
}
示例3: 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.AddMvc()
.AddJsonOptions(
opt => { opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
services.AddLogging();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<JuveDbContext>(options =>
options.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=JuveV;Integrated Security=True"));
services.AddIdentity<ApplicationUser, IdentityRole>(s =>
{
s.Password.RequireDigit = false;
s.Password.RequireUppercase = false;
s.Password.RequiredLength = 3;
s.Password.RequireNonLetterOrDigit = false;
s.Password.RequireLowercase = false;
})
.AddEntityFrameworkStores<JuveDbContext>()
.AddDefaultTokenProviders();
RegisterClasses(services);
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services
.AddDbContext<ApplicationDbContext>(options => options
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services
.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services
.AddMvc()
.AddTypedRouting(routes => routes
.Get("CustomController/{action}", route => route.ToController<ExpressionsController>())
.Get("CustomContact", route => route.ToAction<HomeController>(a => a.Contact()))
.Get("WithParameter/{id}", route => route.ToAction<HomeController>(a => a.Index(With.Any<int>())))
.Get("Async", route => route.ToAction<AccountController>(a => a.LogOff()))
.Get("Named", route => route
.ToAction<AccountController>(a => a.Register(With.Any<string>()))
.WithName("CustomName"))
.Add("Constraint", route => route
.ToAction<AccountController>(c => c.Login(With.Any<string>()))
.WithActionConstraints(new HttpMethodActionConstraint(new[] { "PUT" })))
.Add("MultipleMethods", route => route
.ToAction<HomeController>(a => a.About())
.ForHttpMethods("GET", "POST")));
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
.AddDbContext<TriviaDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
});
}
示例6: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc().AddMvcOptions(options =>
{
options.ModelBinders.Add(new DateTimeModelBinder());
});
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
//
Services.AppSettings.ApiUrl = this.Configuration["AppSettings:API.ConnectionString"];
//
//services.AddMvc().Configure<MvcOptions>(options =>
//{
// options.ModelBinders.Add(typeof(DateTime?), new DateTimeModelBinder());
// options.ModelBinders.Add(typeof(DateTime), new DateTimeModelBinder());
//});
//ModelBinders.Binders.Add(typeof(DateTime?), new DateTimeModelBinder());
//ModelBinders.Binders.Add(typeof(DateTime), new DateTimeModelBinder());
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services, IConfigurationRoot configuration)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Add framework services.
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();
});
// Add CORS support
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
});
services.AddScoped<IUsersRepository, AspNetIdentityUsersRepository>();
services.AddScoped<IUserClaimsRepository, AspNetIdentityUserClaimsRepository>();
}
示例8: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<SiteContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<SiteContext>()
.AddDefaultTokenProviders();
services.AddOptions();
services.Configure<BraintreeSettings>(Configuration.GetSection("AppSettings:Braintree"));
services.Configure<ConstantContactSettings>(Configuration.GetSection("AppSettings:ConstantContact"));
services.AddMvc();
services.AddCaching();
services.AddSession();
services.ConfigureRouting(opts =>
{
opts.AppendTrailingSlash = false;
opts.LowercaseUrls = true;
});
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddScoped<IBookstoreRepository, EFBookstoreRepository>();
}
示例9: ConfigureServices
/// <summary>
/// Configure the ASP.NET Services
/// </summary>
/// <param name="services">The Service Collection</param>
public void ConfigureServices(IServiceCollection services)
{
logger.Trace("Entering ConfigureServices");
// Configure the Entity Framework to use our SQL Server
logger.Trace("Configuring Entity Framework");
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(WebConfiguration.Instance.DatabaseConnectionString));
// Configure ASP.NET Identity Framework to use Entity Framework
logger.Trace("Configuring ASP.NET Identity Framework");
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Use MVC Routing
logger.Trace("Configuring ASP.NET MVC6");
services.AddMvc();
// Add in a transient Razor Service for UserProfile lookup
logger.Trace("Adding Transient Service for User Profile");
services.AddTransient<UserProfile>();
logger.Trace("Leaving ConfigureServices");
}
示例10: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DataContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<User, IdentityRole>(options =>
{
options.Password = new PasswordOptions() {
RequireNonAlphanumeric = false,
RequireUppercase=false
};
}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
// Add framework services.
services.AddMvc();
services.AddTransient<IUserServices, UserServices>();
services.AddTransient<UserServices>();
services.AddMemoryCache();
services.AddAuthorization(options =>
{
options.AddPolicy(
"Admin",
authBuilder =>
{
authBuilder.RequireClaim("Admin", "Allowed");
});
});
}
示例11: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Scoped = Resolve dependency injection
services.AddScoped<LibraryDbContext, LibraryDbContext>();
services.AddScoped<IMediatheekService, MediatheekService>();
services.AddScoped<IRandomUserMeService, RandomUserMeService>();
services.AddScoped<IRandomTextService, RandomTextService>();
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<LibraryDbContext>(options =>
options.UseSqlite(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<LibraryDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Sessions and caching
services.AddCaching();
services.AddSession();
// Ultimate reporting tool
//services.AddGlimpse();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.Get("Data:IdentityConnection:ConnectionString")));
services.Configure<IdentityDbContextOptions>(options =>
{
options.DefaultAdminUserName = Configuration.Get("DefaultAdminUsername");
options.DefaultAdminPassword = Configuration.Get("DefaultAdminPassword");
});
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.ConfigureFacebookAuthentication(options =>
{
options.AppId = "901611409868059";
options.AppSecret = "4aa3c530297b1dcebc8860334b39668b";
});
services.ConfigureGoogleAuthentication(options =>
{
options.ClientId = "514485782433-fr3ml6sq0imvhi8a7qir0nb46oumtgn9.apps.googleusercontent.com";
options.ClientSecret = "V2nDD9SkFbvLTqAUBWBBxYAL";
});
services.ConfigureTwitterAuthentication(options =>
{
options.ConsumerKey = "BSdJJ0CrDuvEhpkchnukXZBUv";
options.ConsumerSecret = "xKUNuKhsRdHD03eLn67xhPAyE1wFFEndFo1X2UJaK2m1jdAxf4";
});
services.AddMvc();
}
示例13: 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.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MyHealthContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddScoped<ApplicationUsersRepository>();
services.AddScoped<ApplicationUserValidators>();
services.AddScoped<PatientsRepository>();
services.AddScoped<ClinicAppointmentsRepository>();
services.AddScoped<ReportsRepository>();
services.AddScoped<HomeAppointmentRepository>();
services.AddScoped<MedicinesRepository>();
services.AddScoped<TipsRepository>();
services.AddScoped<DoctorsRepository>();
services.AddScoped<TenantsRepository>();
services.AddScoped<MyHealthDataInitializer>();
services.AddMvc();
services.AddAuthorization(Policies.Configuration);
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MyHealthContext>()
.AddDefaultTokenProviders();
}
示例14: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) {
// Add Application settings to the services container.
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
// Add EF services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Configure the options for the authentication middleware.
// You can add options for Google, Twitter and other middleware as shown below.
// For more information see http://go.microsoft.com/fwlink/?LinkID=532715
services.Configure<FacebookAuthenticationOptions>(options => {
options.AppId = Configuration["Authentication:Facebook:AppId"];
options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});
services.Configure<MicrosoftAccountAuthenticationOptions>(options => {
options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
});
// Add MVC services to the services container.
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
}
示例15: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>(o =>
{
o.Password.RequireDigit = false;
o.Password.RequiredLength = 6;
o.Password.RequireLowercase = false;
o.Password.RequireNonLetterOrDigit = false;
o.Password.RequireUppercase = false;
o.User.RequireUniqueEmail = true;
o.User.AllowedUserNameCharacters = null;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new
CamelCasePropertyNamesContractResolver();
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddSingleton<ExcelManager>();
services.AddSingleton((e) => Configuration);
}