Advertisement
porkporkpork

startup.cs

Dec 11th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.27 KB | None | 0 0
  1. STARTUP.cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Builder;
  8. using Microsoft.AspNetCore.Identity;
  9. using Microsoft.AspNetCore.Hosting;
  10. using Microsoft.AspNetCore.Http;
  11. using Microsoft.AspNetCore.HttpsPolicy;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.EntityFrameworkCore;
  14. using Workshops.Data;
  15. using Microsoft.Extensions.Configuration;
  16. using Microsoft.Extensions.DependencyInjection;
  17. using Workshops.Models;
  18. using System.Globalization;
  19. using Microsoft.AspNetCore.Mvc.Razor;
  20.  
  21. namespace Workshops
  22. {
  23.     public class Startup
  24.     {
  25.         public Startup(IConfiguration configuration)
  26.         {
  27.             Configuration = configuration;
  28.         }
  29.  
  30.         public IConfiguration Configuration { get; }
  31.  
  32.         // This method gets called by the runtime. Use this method to add services to the container.
  33.         public void ConfigureServices(IServiceCollection services)
  34.         {
  35.             services.Configure<CookiePolicyOptions>(options =>
  36.             {
  37.                 // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  38.                 options.CheckConsentNeeded = context => true;
  39.                 options.MinimumSameSitePolicy = SameSiteMode.None;
  40.             });
  41.  
  42.             services.AddDbContext<ApplicationDbContext>(options =>
  43.                 options.UseSqlServer(
  44.                     Configuration.GetConnectionString("DefaultConnection")));
  45.             services.AddDefaultIdentity<IdentityUser>()
  46.                 .AddEntityFrameworkStores<ApplicationDbContext>();
  47.             services.Configure<IdentityOptions>(options =>
  48.             {
  49.                 options.Password.RequireDigit = false;
  50.                 options.Password.RequireLowercase = false;
  51.                 options.Password.RequireUppercase = false;
  52.                 options.Password.RequireNonAlphanumeric = false;
  53.                 options.Password.RequiredLength = 1;
  54.                 options.User.RequireUniqueEmail = true;
  55.             });
  56.             services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  57.  
  58.             services.AddMvc().AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix).AddDataAnnotationsLocalization();
  59.  
  60.             services.AddDbContext<TheatersContext>(options =>
  61.                     options.UseSqlServer(Configuration.GetConnectionString("TheatersContext")));
  62.             services.AddLocalization(options => options.ResourcesPath = "Resources");
  63.             services.AddCors(options =>
  64.     {
  65.                 options.AddPolicy("AllowAllOrigins",
  66.                 builder =>
  67.     {
  68.                     builder.AllowAnyOrigin();
  69.                 });
  70.             });
  71.  
  72.         }
  73.  
  74.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  75.         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  76.         {
  77.  
  78.             var supportedCultures = new[]
  79.             {
  80.                 new CultureInfo("nl"),
  81.                 new CultureInfo("en-US"),
  82.                 new CultureInfo("en"),
  83.                 new CultureInfo("fr-FR"),
  84.                 new CultureInfo("fr"),
  85.             };
  86.             app.UseRequestLocalization(new RequestLocalizationOptions
  87.             {
  88.                 DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("nl"),
  89.                 SupportedCultures = supportedCultures,
  90.                 SupportedUICultures = supportedCultures
  91.             });
  92.             if (env.IsDevelopment())
  93.             {
  94.                 app.UseDeveloperExceptionPage();
  95.                 app.UseDatabaseErrorPage();
  96.             }
  97.             else
  98.             {
  99.                 app.UseExceptionHandler("/Home/Error");
  100.                 app.UseHsts();
  101.             }
  102.  
  103.             app.UseHttpsRedirection();
  104.             app.UseStaticFiles();
  105.             app.UseCookiePolicy();
  106.  
  107.             app.UseAuthentication();
  108.  
  109.             app.UseMvc(routes =>
  110.             {
  111.                 routes.MapRoute(
  112.                     name: "default",
  113.                     template: "{controller=Home}/{action=Index}/{id?}"); //dit was mogelijk fout en moest misschien newsmessages zijn ipv home
  114.             });
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement