@@ -149,11 +149,9 @@ public static async Task Main(string[] args)
149149 builder . Services . AddAntiforgery ( options =>
150150 {
151151 options . HeaderName = "X-CSRF-TOKEN" ;
152- // Use HTTPS only in production; allow HTTP in development/testing
152+ // Use HTTPS only in production; allow HTTP in development
153153 options . Cookie . HttpOnly = true ;
154- options . Cookie . SecurePolicy = builder . Environment . IsProduction ( )
155- ? CookieSecurePolicy . Always
156- : CookieSecurePolicy . SameAsRequest ;
154+ options . Cookie . SecurePolicy = CookieSecurePolicy . Always ;
157155 options . Cookie . SameSite = SameSiteMode . Strict ;
158156 } ) ;
159157
@@ -267,9 +265,7 @@ public static async Task Main(string[] args)
267265 builder . Services . ConfigureApplicationCookie ( options =>
268266 {
269267 options . Cookie . HttpOnly = true ; // Prevent XSS access to cookie
270- options . Cookie . SecurePolicy = builder . Environment . IsProduction ( )
271- ? CookieSecurePolicy . Always
272- : CookieSecurePolicy . SameAsRequest ;
268+ options . Cookie . SecurePolicy = CookieSecurePolicy . Always ; // HTTPS only
273269 options . Cookie . SameSite = SameSiteMode . Strict ; // Prevent CSRF
274270 options . ExpireTimeSpan = TimeSpan . FromMinutes ( 30 ) ; // Session timeout
275271 options . SlidingExpiration = true ; // Extend on activity
@@ -434,7 +430,10 @@ public static async Task Main(string[] args)
434430 pattern : "{controller=Home}/{action=Index}/{id?}" ) ;
435431 #endregion
436432
437- await ApplyDatabaseMigrationsAndSeedAsync ( app ) ;
433+ if ( ! app . Environment . IsEnvironment ( "Testing" ) )
434+ {
435+ await ApplyDatabaseMigrationsAndSeedAsync ( app ) ;
436+ }
438437
439438 app . Run ( ) ;
440439 }
0 commit comments