Open Closed

How to enable CookieConsent for public web #9163


User avatar
0
ageiter created

Hi,

I can activate the cookie consent message in the Blazor app.

But how does this work with the public website (MVC)?

Thanks, Adrian


10 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, if you are using the GDPR module in your public web application, you can configure the AbpCookieConsentOptions:

    Configure<AbpCookieConsentOptions>(options => 
    {
        IsEnabled = true;
        CookiePolicyUrl = "/CookiePolicy";
        PrivacyPolicyUrl = "/PrivacyPolicy";
        Expiration = TimeSpan.FromDays(180);
    });
    

    For further info, you can refer to the documentation: https://abp.io/docs/latest/modules/gdpr

  • User Avatar
    0
    ageiter created

    Thank you for the very quick reply.

    The problem is probably because this module is only integrated in the Blazor app, but not yet in MyProject.Web.Public.

    But your code does not work for me when I want to insert it in MyProjectWebPublicModule.

    I have to adapt it as follows:

            Configure<AbpCookieConsentOptions>(options => 
            {
                options.IsEnabled = true;
                options.CookiePolicyUrl = "/CookiePolicy";
                options.PrivacyPolicyUrl = "/PrivacyPolicy";
            });
    

    But this compiles but the options are never set and it doesn't work either....

  • User Avatar
    0
    ageiter created

    Thank you for the very quick reply.

    The problem is probably because this module is only integrated in the Blazor app, but not yet in MyProject.Web.Public.

    But your code does not work for me when I want to insert it in MyProjectWebPublicModule.

    I have to adapt it as follows:

            Configure<AbpCookieConsentOptions>(options => 
            {
                options.IsEnabled = true;
                options.CookiePolicyUrl = "/CookiePolicy";
                options.PrivacyPolicyUrl = "/PrivacyPolicy";
            });
    

    But this compiles but the options are never set and it doesn't work either....

    Which package do I need to have in the project? Volo.Abp.Gdpr.Abstractions?

  • User Avatar
    0
    ageiter created

    I have now installed it with the Abp Studio (Volo.Abp.Gdpr.Web), but unfortunately it still does not work.

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    I have now installed it with the Abp Studio (Volo.Abp.Gdpr.Web), but unfortunately it still does not work.

    Yes, this is the correct package to add to your public web project. If the cookie consent still doesn't appear, it's possible that there's an entry in your localStorage with the value set to 'dismiss'. Please check your localStorage, clear it if possible, and try again to see if the consent banner is displayed.

  • User Avatar
    0
    ageiter created

    But when I make a breakpoint in the options (options.IsEnabled), the debugger doesn't break... I think, something else is wrong...

  • User Avatar
    0
    ageiter created

    Yes, this is the correct package to add to your public web project. If the cookie consent still doesn't appear, it's possible that there's an entry in your localStorage with the value set to 'dismiss'. Please check your localStorage, clear it if possible, and try again to see if the consent banner is displayed.

    Clearing the local storage cache did not help...

    That's my code:

    I set a breakpoint on line 115, but never get there.

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, instead of just configuring the option, use the AddAbpCookieConsent method to register services & register the related component to the layout:

    context.Services.AddAbpCookieConsent(options =>
    {
        options.IsEnabled = true;
        options.CookiePolicyUrl = "/CookiePolicy";
        options.PrivacyPolicyUrl = "/PrivacyPolicy";
    });
    

    If you only configure the option, then it has no effect. So, you should call AddAbpCookieConsent to inject the component to the layout.

    Btw, you should also add app.UseAbpCookieConsent() in your request pipeline.

  • User Avatar
    0
    ageiter created

    Ok, now the breakpoint works inside of AddAbpCookieConsent

    At first, however, nothing appeared on the website (just an empty AbpCookieConsent widget).

    Btw, you should also add app.UseAbpCookieConsent() in your request pipeline.

    To add app.UseAbpCookieConsent() in the OnApplicationInitialization method makes the difference. This is very important. And the order is also very important. I had it at the end first, but that didn't work. Now I have it after app.UseAuthentication(); and then it works.

    Some very important information that I think is missing in the documentation. Please add them so that others don't stumble across the same errors.

    Thank you @EngincanV for your help.

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Ok, now the breakpoint works inside of AddAbpCookieConsent

    At first, however, nothing appeared on the website (just an empty AbpCookieConsent widget).

    Btw, you should also add app.UseAbpCookieConsent() in your request pipeline.

    To add app.UseAbpCookieConsent() in the OnApplicationInitialization method makes the difference. This is very important. And the order is also very important. I had it at the end first, but that didn't work. Now I have it after app.UseAuthentication(); and then it works.

    Some very important information that I think is missing in the documentation. Please add them so that others don't stumble across the same errors.

    Thank you @EngincanV for your help.

    Hi, thanks for pointing that out. Indeed, it seems we forgot to mention that. I'll update the documentation.

    Regards.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on May 12, 2025, 05:22