TempData not working when published to Azure

不羁岁月 提交于 2019-12-01 19:10:31

Ran into the same issue.

Turned on streaming logs on azure and found the following message:

Microsoft.AspNetCore.CookiePolicy.CookiePolicyMiddleware: Cookie '.AspNetCore.Mvc.CookieTempDataProvider' suppressed due to consent policy

Turns out when I was scaffolding my site I stripped the GDPR Cookie Consent code that comes out of the box in .net Core MVC apps that will create the .AspNet.Consent cookie (with a value of "yes") when accepted.

Once that cookie was created, TempData started working.

You can also update the cookie policy options to not check for consent by setting CheckConsentNeeded to false if you are not subject to GDPR.

 services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => false;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!