Base solution for your next web application
Open Closed

Remove Cache-Control header #10449


User avatar
0
mahendra created

Prerequisites

  • What is your product type (Angular or MVC)?
  • Angular
  • What is product framework type (.net framework or .net core)?
  • .net core

Hi Experts,

We have hosted our asp.net zero web application(.net core + angular) on AWS Beanstalk-LINUX based node.js environment. We have a requirement to change the Cache-control to max-size = 31536000. As our angular application hosted on AWS Beanstalk-LINUX based node.js environment, With the help of the AWS support we are able to achieve the same using the below nginx.conf file.

---------nginx.conf Start---------------------------------------------------------------------

`#Elastic Beanstalk Nginx Configuration File

user nginx; errorlog /var/log/nginx/error.log warn; pid /var/run/nginx.pid; workerprocesses auto; workerrlimitnofile 32633;

events { workerconnections 1024; }

http { include /etc/nginx/mime.types; defaulttype application/octet-stream;

logformat  main  '$remoteaddr - $remoteuser [$timelocal] "$request" '
                  '$status $bodybytessent "$httpreferer" '
                  '"$httpuseragent" "$httpxforwardedfor"';

include       conf.d/.conf;

map $httpupgrade $connectionupgrade {
    default     "upgrade";
}

#------------------------------------------------------------------------

Map blocks to set value of $control and $expires variable based on the $uri

map $cache $control { 1 "public"; }

map $cache $expires { 1 31536000; default off; # or some other default value }

map $uri $cache { ~.(js|css|png|jpe?g|gif|ico)$ 1; } #----------------------------------------------------------------

server {
    listen        80 defaultserver;
    accesslog    /var/log/nginx/access.log main;

    clientheadertimeout 60;
    clientbodytimeout   60;
    keepalivetimeout     60;
    gzip                  off;
    gzipcomplevel       4;
    gziptypes text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
   
   
   #---------------------------------
   # Adding Cache-Control headers
   addheader Cache-Control "$control,max-age=$expires";
   #---------------------------------

    # Include the Elastic Beanstalk generated location
    include conf.d/elasticbeanstalk/.conf;
}

}`

------------nginx.conf End-------------------------------------------------------

Now as you can see in the below screen shot that cache-control max-size is set to 31536000. However we are also getting the cache-control:public, max-age=0.

As per AWS support, these response headers are coming from application itself and we are not aware from where in our aspnet zero application we are setting these response headers or how to remove them.

Could you please help us in removing the cache-control response header with the max-age=0.

We also checked the below option. https://support.aspnetzero.com/QA/Questions/10428/Removeoverride-cache-control-property-from-the-Response-Header But visual studio does not recognize the DefaultResponseCacheAttributeForAppServices/ DefaultResponseCacheAttributeForControllers

Any help would be much appreciated.

Thanks, Regards


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    Could you please follow https://github.com/aspnetboilerplate/aspnetboilerplate/issues/6168. We will work on this in a short time.

  • User Avatar
    0
    mahendra created

    hi ismcagdas,

    Thanks for your response.

    I have gone through the link shared by you. Just to let you know that we use the services. Might be the framework itself would be creating the controller based on the naming convention.

    Currently we are using aspnetboilerplate version 5.2 and .Net Core 3.1. As we are about to release our product in near future. Therefore, it may take some time for us to upgrade to the latest aspnetboilerplate version + .Net 5.

    We also noticed in that link that even after upgrading to the latest version issue is still open.

    Could you please give us your sincere opinion how to proceed?

    Thanks, Best Regards,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    You don't have to upgrade your solution to latest ABP version. We will try to provide a solution without upgrading the NuGet packages. I assume this issue will be resolved until the end of this month.

  • User Avatar
    0
    mahendra created

    Hi ismcagdas,

    I hope you are well.

    Any update for us..As last month is over..We are waiting for your response..

    Thanks Best Regards,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    We are currently working on this and will update you about the problem in a few days. Sorry for the delay in this issue.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    I figred out the problem, please check my comment

  • User Avatar
    0
    mahendra created

    Hi ismcagdas,

    Thanks for your response.

    We read your comment and found AbpAntiForgeryManager.SetCookie(Context) at following places in our project:

    OneEnterprise.iHUB.Web.Host\Views\Ui\Index.cshtml OneEnterprise.iHUB.Web.Host\Views\Ui\Login.cshtml OneEnterprise.iHUB.Web.Public\Views\Layout_ Layout.cshtml

    Do you want us to remove AbpAntiForgeryManager.SetCookie(Context) from above files and check whether cache-control response header is removed with max-age=0

    Note: We are using Angular + .Net core application.

    Thanks, Best Regards

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    sorry, I thought you were using the MVC version, could you duplicate the AbpHttpInterceptor with a different name and use it in your project ?

    I think you can change this line to achieve what you want.

    Then, you can search for AbpHttpInterceptor in your project and replace it with the one you created.