Turn off the GDPR cookie notification in a dotnet core MVC web application

The dotnet core MVC web application template adds the GDPR cookie acceptance message to the header of the page template. When the site is hosted with HTTP the accept button does not clear the message resulting an infinite loop, when the user cannot log in and the site continuously asks for the acceptance.

When the site is hosted in a Docker container it is also simpler to instal the SSL certificate on the load balancer and host the site with HTTP on port 80.

We use cookies. To be able to use this site please click the Accept button.

To remove the feature delete the

<partial name="_CookieConsentPartial" />

line from the Views\Shared\Layout.cshtml file.

Without the acknowledgement the dotnet core framework will not save any non essential cookies in the browser, so the session state will stop working.

To tell the dotnet core framework, that the application does not require the user to allow the saving of the cookies set the value of CheckConsentNeeded to false in the ConfigureServices() method, services.Configure<CookiePolicyOptions> { section

options.CheckConsentNeeded = context => false;

To make sure the session cookie is always saved even if the GDPR confirmation is enabled, declare it to essential in the ConfigureServices() method, services.AddSession(options => { section

options.Cookie.IsEssential = true;

Leave a comment

Leave a Reply