Skip to content

Outputcache doesn't work when a cookie is set #23

@arnvanhoutte

Description

@arnvanhoutte

I have a custom localization middleware where I set the current culture in a cookie:

                context.Response.Cookies.Append(
                    CookieRequestCultureProvider.DefaultCookieName,
                    CookieRequestCultureProvider.MakeCookieValue(
                        new RequestCulture(culture, culture)));

If I add this code then the outputcache stops working. This was also a problem in .NET Framework's OutputCache but the workaround was making the cookie shareable https://docs.microsoft.com/en-us/dotnet/api/system.web.httpcookie.shareable?redirectedfrom=MSDN&view=netframework-4.8#System_Web_HttpCookie_Shareable

However it doesn't seem like this works here.

EDIT:

I notice that this setup works but what the reason that cookies are blocked in the first place?

        services.AddOutputCaching(options => options.DoesResponseQualify = (context) =>
        {
            if (context.Response.StatusCode != StatusCodes.Status200OK) return false;
            //if (context.Response.Headers.ContainsKey(HeaderNames.SetCookie)) return false; ENABLING COOKIES

            return true;
        });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions