update panel CSV generation cache issue - asp.net

On a page with update panel on a button click I have put some code to generate CSV .
When I click on Open in File dialog CSV file shown comes from browser cache.Every time it shows old csv.I have checked on server the csv file is created new but browser show old files.

Rather than impractical work arounds, you should instead focus on changing the servers cache control settings, provided you are on an apache server, then update your .htaccess file with:
<filesMatch "\.(csv)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
This will switch off caching of .csv files.

A Simple way to avoid that is to add a random string on the end of the file, something like
/YourFile.csv?rnd=4707
or you can place some cache headers to not let it cache, for example
Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-4));
Response.Cache.SetNoStore();
Response.Cache.SetValidUntilExpires(false);
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Related

Allow Wordpress installed with Docker on Azure to be embeded as iframe

I created a simple webapp container with the image wordpress:latest on linux on azure.
Everything works fine. Now I tried to embed this website in a website which I am working on running on my localhost:port.
Since I don't have access to SSH to edit the wp-config.php or .htaccess (it's anyways in the docker container) I installed the plugin wp-htaccess-editor to have access to the .htaccess (it really has access... I did changes and checked with another plugin..)
# BEGIN HttpHeaders
# The directives (lines) between "BEGIN HttpHeaders" and "END HttpHeaders" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_headers.c>
<IfModule mod_setenvif.c>
SetEnvIf Origin "^(.+)$" CORS=$0
</IfModule>
Header set Access-Control-Allow-Origin %{CORS}e env=CORS
<FilesMatch "\.(php|html)$">
Header set X-Frame-Options "ALLOW-FROM http://192.....:5174"
</FilesMatch>
</IfModule>
# END HttpHeaders
But I still get the error:
Refused to display 'http://goofyPage.azurewebsites.net' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
But it is not true that x-frame-options is set to sameorigin.. it is set allow-from myLocalIP. => Somehow can it be that nginx overrides this option? since when I check the header data it is really still "sameorigin"...
What are my options to make this work? Should I add the header option also on Azure on my webApp->configuration->Application settings??
When I check https://goofyPage.scm.azurewebsites.net/Env#httpHeaders
AppSettings
Header = set X-Frame-Options ALLOW-FROM http://192...:5174
...
Environment variables
APPSETTING_Header = set X-Frame-Options ALLOW-FROM http://192....:5174
Header = set X-Frame-Options ALLOW-FROM http://192.....:5174

Clear cache for static website upon deploy with Heroku?

I have a static website hosted with Heroku's hobby tier. I have an issue where everytime I push a new deployment from my GitHub repository, my stylesheet doesn't update for hours (even though my HTML does). As the stylesheet displays correctly on an incognito tab and after clearing "Cached Images and Files," I assume locally cached website files are the issue. Is there a way to bypass this in order to update my CSS stylesheet after every deploy?
My stylesheet is ~600 lines if it matters.
Adding the following to my htaccess file worked for me.
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
This prevents caching for HTML, HTM, JS, and CSS files.

Wordpress / Prevent Server from Caching CSV Files

I am creating a CSV File with PHP and save it to the Server.
The Server Cache is enabled, but this makes the CSV File being cached too.
I am looking for a way to prevent that. Without Plugins...
What I tried: adding code to htaccess (which also prevents the browser from caching the file, please don#t focus on answers related to htaccess and browser-caching, thanks!).
And I also tried to add some header() Code .. but I am not sure where.
I added this when I create the File:
header('Content-Type: text/csv');
header('Content-Disposition: attachment filename="sample.csv"');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
But it's not working when I open the file - it gets cached. But I guess this is the false spot for adding this code. But where else?
I also tried to add an action to 'init' and ask if the called file is the file I don't want to be cached, but of course, functions.php is not called when opening a file from the server.
Does someone have an Idea?
Put this code in .htaccess file , it may help you . prior puting this make sure you have done backup of your website.
<FilesMatch "\.(pdf|csv|doc)$">
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
<IfModule mod_headers.c>
FileETag None
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
</IfModule>
</FilesMatch>

Caching not being done only for png and jpg images

Given below is the code in my .htaccess file. On checking PageSpeed Insights, it still tells me to Leverage browser caching only for my png and jpg files. Could someone point out what could be wrong with the code? Would appreciate help! (The site is using a wordpress theme)
<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|svg)$">
Header set Expires "Wed, 15 Apr 2020 20:00:00 GMT"
Header set Cache-Control "public"
</FilesMatch>
</IfModule>
Assuming it is working correctly for the other extensions, my best guess is that perhaps your .jpg and .png files have uppercase letters in their extension (e.g. .JPG or .PNG). If that's the case try making your FilesMatch regular expression be case insensitive (see How to make this .htaccess rule case insensitive?).

Drupal 7.0 caching problem!

I've just finished a drupal project and I'm going through optimization phase of the site. I've checked cache blocks and CSS and JS aggregation under performance for better load time . but something I noticed, when I run a page speed test or Yslow everything passes but Leverage browser caching. It seems like the expiry date is not set on all the images and css files. My question is do I have to edit .htaccess file or do I need to place the images and css files that are not cached into a particular folder?
Any help is appreciated, many thanks in advance
You can configure Apache to set specific expire / cache control headers for your image/css/js files using mod_expires and mod_headers.
Here are few examples (general examples -- analyse and consult the manual before applying to your system):
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>
</FilesMatch>
Caching with both mod_expires + mod_headers
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>
# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
I had the same issue for a long time and I just found the trick!
After looking in .htaccess located on drupal's root repository, there is this condition :
<IfModule mod_expires.c> ... </IfModule>
The code located inside is not executed because apache's expires_module is just not enable on my server, check if expires_module is present on list returned by :
sudo apache2ctl -M
If not, just activate it by :
sudo a2enmod expires
sudo a2enmod headers
sudo service apache2 restart

Resources