forked from dotnet/AspNetCore.Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ASP.NET Core 2 features to Identity Configuration. (dotnet#4288)
* Add ASP.NET Core 2 features to Identity Configuration. Fixed typo with ASP.NET Core 1 Cookie Name. * Make things more clear and call out the specific options. * Fix wording, spacing, typo on folder name. Display 1.x snippets with more context * Fix typo * Move properties and call out ASP.NET Core 1.x ones.
- Loading branch information
1 parent
12f2df9
commit 76d42f0
Showing
8 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ecurity/authentication/identity/sample/src/ASPNETv2-IdentityDemo-Configuration/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using WebApplication5.Data; | ||
using WebApplication5.Models; | ||
using WebApplication5.Services; | ||
|
||
namespace WebApplication5 | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
#region snippet_configureservices | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddDbContext<ApplicationDbContext>(options => | ||
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); | ||
|
||
services.AddIdentity<ApplicationUser, IdentityRole>(options => | ||
{ | ||
// Password settings | ||
options.Password.RequireDigit = true; | ||
options.Password.RequiredLength = 8; | ||
options.Password.RequireNonAlphanumeric = true; | ||
options.Password.RequireUppercase = true; | ||
options.Password.RequireLowercase = true; | ||
options.Password.RequiredUniqueChars = 2; | ||
|
||
// Lockout settings | ||
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); | ||
options.Lockout.MaxFailedAccessAttempts = 5; | ||
options.Lockout.AllowedForNewUsers = true; | ||
|
||
// Signin settings | ||
options.SignIn.RequireConfirmedEmail = true; | ||
options.SignIn.RequireConfirmedPhoneNumber = false; | ||
|
||
// User settings | ||
options.User.RequireUniqueEmail = true; | ||
}) | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddDefaultTokenProviders(); | ||
|
||
#region snippet_ConfigureCookie | ||
services.ConfigureApplicationCookie(options => | ||
{ | ||
options.Cookie.Name = "YourAppCookieName"; | ||
options.Cookie.HttpOnly = true; | ||
options.ExpireTimeSpan = TimeSpan.FromMinutes(60); | ||
options.LoginPath = "/Account/Login"; | ||
options.LogoutPath = "/Account/Logout"; | ||
options.AccessDeniedPath = "/Account/AccessDenied"; | ||
options.SlidingExpiration = true; | ||
}); | ||
#endregion | ||
|
||
// Add application services. | ||
services.AddTransient<IEmailSender, EmailSender>(); | ||
|
||
services.AddMvc(); | ||
} | ||
#endregion | ||
|
||
#region snippet_configure | ||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
app.UseBrowserLink(); | ||
app.UseDatabaseErrorPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
} | ||
|
||
app.UseStaticFiles(); | ||
|
||
app.UseAuthentication(); | ||
|
||
app.UseMvc(routes => | ||
{ | ||
routes.MapRoute( | ||
name: "default", | ||
template: "{controller=Home}/{action=Index}/{id?}"); | ||
}); | ||
} | ||
#endregion | ||
} | ||
} |