11using Microsoft . AspNetCore . Builder ;
22using Microsoft . AspNetCore . Hosting ;
3- using Microsoft . AspNetCore . Http ;
4- using Microsoft . AspNetCore . Mvc ;
5- using Microsoft . Extensions . Configuration ;
63using Microsoft . Extensions . DependencyInjection ;
4+ using Microsoft . Extensions . Hosting ;
75using Serilog ;
86
97namespace EarlyInitializationSample
108{
119 public class Startup
1210 {
13- public Startup ( IConfiguration configuration )
14- {
15- Configuration = configuration ;
16- }
17-
18- public IConfiguration Configuration { get ; }
19-
20- // This method gets called by the runtime. Use this method to add services to the container.
2111 public void ConfigureServices ( IServiceCollection services )
2212 {
23- services . Configure < CookiePolicyOptions > ( options =>
24- {
25- // This lambda determines whether user consent for non-essential cookies is needed for a given request.
26- options . CheckConsentNeeded = context => true ;
27- options . MinimumSameSitePolicy = SameSiteMode . None ;
28- } ) ;
29-
30-
31- services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 ) ;
13+ services . AddControllersWithViews ( ) ;
3214 }
3315
34- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
35- public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
16+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
3617 {
3718 if ( env . IsDevelopment ( ) )
3819 {
@@ -41,21 +22,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
4122 else
4223 {
4324 app . UseExceptionHandler ( "/Home/Error" ) ;
25+ app . UseHsts ( ) ;
4426 }
4527
28+ app . UseStaticFiles ( ) ;
29+
4630 // Write streamlined request completion events, instead of the more verbose ones from the framework.
4731 // To use the default framework request logging instead, remove this line and set the "Microsoft"
4832 // level in appsettings.json to "Information".
4933 app . UseSerilogRequestLogging ( ) ;
5034
51- app . UseStaticFiles ( ) ;
52- app . UseCookiePolicy ( ) ;
35+ app . UseRouting ( ) ;
5336
54- app . UseMvc ( routes =>
37+ app . UseEndpoints ( endpoints =>
5538 {
56- routes . MapRoute (
39+ endpoints . MapControllerRoute (
5740 name : "default" ,
58- template : "{controller=Home}/{action=Index}/{id?}" ) ;
41+ pattern : "{controller=Home}/{action=Index}/{id?}" ) ;
5942 } ) ;
6043 }
6144 }
0 commit comments