Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Identity;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.AspNetCore.Http;
  9. using Microsoft.AspNetCore.HttpsPolicy;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.EntityFrameworkCore;
  12. using Chushka.Data;
  13. using Microsoft.Extensions.Configuration;
  14. using Microsoft.Extensions.DependencyInjection;
  15. using Chushka.Models;
  16. using Chushka.Utilities;
  17.  
  18. namespace Chushka
  19. {
  20. public class Startup
  21. {
  22. public Startup(IConfiguration configuration)
  23. {
  24. Configuration = configuration;
  25. }
  26.  
  27. public IConfiguration Configuration { get; }
  28.  
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.Configure<CookiePolicyOptions>(options =>
  32. {
  33. options.CheckConsentNeeded = context => true;
  34. options.MinimumSameSitePolicy = SameSiteMode.None;
  35. });
  36.  
  37. services.AddDbContext<ChushkaDbContext>(options =>
  38. options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  39.  
  40. //services.AddDefaultIdentity<IdentityUser>()
  41. // .AddEntityFrameworkStores<ChushkaDbContext>();
  42.  
  43. //Горе премахвам дефолтното Айдентити и казвам - нашето айдентити ще е от ChushkaUser, който ще използва IdentityRole
  44. services.AddIdentity<ChushkaUser, IdentityRole>(options =>
  45. {
  46. options.SignIn.RequireConfirmedEmail = false;
  47. options.Password.RequireLowercase = false;
  48. options.Password.RequireUppercase = false;
  49. options.Password.RequireNonAlphanumeric = false;
  50. options.Password.RequireDigit = false;
  51. options.Password.RequiredUniqueChars = 0;
  52. options.Password.RequiredLength = 3;
  53. })
  54. .AddDefaultUI()
  55. .AddDefaultTokenProviders()
  56. .AddEntityFrameworkStores<ChushkaDbContext>();
  57.  
  58. //Сетвам някой дефолтно пътища
  59. services.ConfigureApplicationCookie(options =>
  60. {
  61. options.LoginPath = "/Account/Login";
  62. //options.LogoutPath = "Identity/Account/Logout";
  63. //options.AccessDeniedPath = "/Account/AccessDenied";
  64. });
  65.  
  66. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  67. }
  68.  
  69. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  70. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider provider)
  71. {
  72. if (env.IsDevelopment())
  73. {
  74. app.UseDeveloperExceptionPage();
  75. app.UseDatabaseErrorPage();
  76. }
  77. else
  78. {
  79. app.UseExceptionHandler("/Home/Error");
  80. app.UseHsts();
  81. }
  82.  
  83. Seeder.Seed(provider); //Тук сийдвам ролите
  84.  
  85. app.UseHttpsRedirection();
  86. app.UseStaticFiles();
  87. app.UseCookiePolicy();
  88.  
  89. app.UseAuthentication();
  90.  
  91. app.UseMvc(routes =>
  92. {
  93. routes.MapRoute(
  94. name: "default",
  95. template: "{controller=Home}/{action=Index}/{id?}");
  96. });
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement