asp.net-core-mvccache-controlasp.net-core-webapiresponsecache

ASP.Net Core Web API - ResponseCache attribute is not adding "Cache-Control" header to the reponse


I have multiple controllers in my ASP .NET Core application and I am using ReponseCache attribute like this on a few methods:

//controller 
[Route("api/[controller]")]
[EnableCors("CorsPolicy")]
public class InsightsApiController : Controller

//method    
[Route("CoursesTextContent")]
[HttpGet]
[DecryptFilter]
[ResponseCache(Duration = 60)]
public IActionResult GetCoursesContent(string locale, string tabKey, string widgetType)

The issue that I am having is that for one controller this is working fine and I can see the response in chrome dev tools with "Cache-Control:public max-age=60" but in a different controller when I add this attribute its adding "Cache-Control:no-cache". I compared both controllers and methods in them and they are configured same. I have also tried to add ASP.NET Core middleware recommended here but same results. I am calling both methods from Angular2 webpage. Is there something I can do from the client side (request)? or something in the ASP.NET Core app setup?


Solution

  • I had a session middleware enabled in the startup.cs file of my ASNETCore webapi project. I removed it and its working for all calls/controllers now. Not sure why it was causing problem only with one Controller.