Advertisement
wingman007

2018_DotNetProgrammingPartTime_Startup.cs

Sep 25th, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 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.Hosting;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.AspNetCore.HttpsPolicy;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Microsoft.EntityFrameworkCore;
  11. using Microsoft.Extensions.Configuration;
  12. using Microsoft.Extensions.DependencyInjection;
  13. using Microsoft.Extensions.Logging;
  14.  
  15. namespace WebApplication1bDeletMe
  16. {
  17.     public class Startup
  18.     {
  19.         public Startup(IConfiguration configuration)
  20.         {
  21.             Configuration = configuration;
  22.         }
  23.  
  24.         public IConfiguration Configuration { get; }
  25.  
  26.         // This method gets called by the runtime. Use this method to add services to the container.
  27.         public void ConfigureServices(IServiceCollection services)
  28.         {
  29.             services.Configure<CookiePolicyOptions>(options =>
  30.             {
  31.                 // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  32.                 options.CheckConsentNeeded = context => true;
  33.                 options.MinimumSameSitePolicy = SameSiteMode.None;
  34.             });
  35.  
  36.             services.AddDbContext<AppDbContext>(options => options.UseInMemoryDatabase("name"));
  37.  
  38.             services.AddLogging();
  39.  
  40.             services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  41.         }
  42.  
  43.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  44.         public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  45.         {
  46.             loggerFactory.AddConsole();
  47.             loggerFactory.AddDebug();
  48.  
  49.             if (env.IsDevelopment())
  50.             {
  51.                 app.UseDeveloperExceptionPage();
  52.             }
  53.             else
  54.             {
  55.                 app.UseExceptionHandler("/Error");
  56.                 app.UseHsts();
  57.             }
  58.  
  59.             app.UseHttpsRedirection();
  60.             app.UseStaticFiles();
  61.             app.UseCookiePolicy();
  62.  
  63.             app.UseMvc();
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement