Skip to content

Commit 0c43b2c

Browse files
committed
[ASP.NET Core] Fixed cookie consent
1 parent 6afc455 commit 0c43b2c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ASP.NET Core/Web/AspNetCoreTemplate.Web/Startup.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using Microsoft.AspNetCore.Builder;
1717
using Microsoft.AspNetCore.Hosting;
18+
using Microsoft.AspNetCore.Http;
1819
using Microsoft.EntityFrameworkCore;
1920
using Microsoft.Extensions.Configuration;
2021
using Microsoft.Extensions.DependencyInjection;
@@ -32,7 +33,6 @@ public Startup(IConfiguration configuration)
3233
// This method gets called by the runtime. Use this method to add services to the container.
3334
public void ConfigureServices(IServiceCollection services)
3435
{
35-
// Framework services
3636
services.AddDbContext<ApplicationDbContext>(
3737
options => options.UseSqlServer(this.configuration.GetConnectionString("DefaultConnection")));
3838

@@ -46,6 +46,14 @@ public void ConfigureServices(IServiceCollection services)
4646
options.Password.RequiredLength = 6;
4747
}).AddRoles<ApplicationRole>().AddEntityFrameworkStores<ApplicationDbContext>();
4848

49+
50+
services.Configure<CookiePolicyOptions>(
51+
options =>
52+
{
53+
options.CheckConsentNeeded = context => true;
54+
options.MinimumSameSitePolicy = SameSiteMode.None;
55+
});
56+
4957
services.AddControllersWithViews();
5058
services.AddRazorPages();
5159

@@ -92,10 +100,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
92100

93101
app.UseHttpsRedirection();
94102
app.UseStaticFiles();
103+
app.UseCookiePolicy();
95104

96105
app.UseRouting();
97106

98-
app.UseCookiePolicy();
99107
app.UseAuthentication();
100108
app.UseAuthorization();
101109

ASP.NET Core/Web/AspNetCoreTemplate.Web/Views/Shared/_CookieConsentPartial.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@if (showBanner)
1010
{
1111
<div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert">
12-
Use this space to summarize your privacy and cookie use policy. <a asp-area="" asp-controller="Home" asp-action="Privacy">Learn More</a>.
12+
We use cookies to understand how you use our site and to improve your experience. <a asp-area="" asp-controller="Home" asp-action="Privacy">Learn More</a>.
1313
<button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
1414
<span aria-hidden="true">Accept</span>
1515
</button>

0 commit comments

Comments
 (0)