It's a bit unusual question, but the 3rd party app we're using is having all textual files without an extension (.js, .css, etc...).
Is there a way to specify a directory where compression is mandatory for all files?
Sounds like your looking for the <location> element. You set the site wide defaults as normal, then add a <location path="x"> element with the folder specific settings and they are only applied to the path specified (and its children).
<configuration>
...
<system.webServer>
<httpCompression ...>
<!-- Site wide default compression settings -->
</httpCompression>
</system.webServer>
...
<location path="path/to/folder" >
<system.webServer>
<httpCompression ...>
<!-- override settings for requests starting "path/to/folder" -->
</httpCompression>
</system.webServer>
</location>
</configuration>
Related
Our default website in IIS has a folder in it that houses a web-application. There are several applications and we want to limit the effect to only the one:
> c:\inetpub\wwwroot\foo
There are folders beneath \foo, each of which has an HTML page of the same name:
> foo
sis
publish.htm
boom
publish.htm
bah
publish.htm
These publish.htm files will be edited from time to time. We want to prevent them from being cached in Microsoft Edge. They are ClickOnce files and only Edge v92 or later will be used to open them.
Could this web.config be placed in each of the child folders, sis, boom, and bah? Is there a way of putting it in folder foo and editing the path so it includes any path that leads to any file called publish.htm?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="publish.htm">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
I have a c# ASP.Net application with an NGINX server as a reversed proxy in front of it. I add a version query parameter for every CSS and JS file I include and all images are immutable. For some JS files however I can't add these parameters so NGINX will cache them for the entire length of the cache control header.
It is possible to overrule the cache control header for proxies by setting the X-Accel-Expires header. However, I don't know how to do this in IIS (web.config) and can't find out either. Does anyone know?
Here's a configuration in the root web.config, it simply adds X-Accel-Expires: 10 for assets/jquery-1.10.1.min.js.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="assets/jquery-1.10.1.min.js">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Accel-Expires" value="10" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
For more information: Custom Headers <customHeaders>
I have a temporary directory at:
c:\inetpub\mysite\temp\
I build a text file dynamically and save it to that directory. Then I have the users browser download that file by putting it into an iframe. This works fine for files that the browser can't open (.doc, .zip) but because I'm using a .txt file the browser just opens it. e.g. It never goes through the normal download process where you can pick where you want to have it downloaded.
A little research and I found you can put a web.config in the same directory as the file to configure the HTTP headers and then do something like:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".txt" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
But when I do that I get Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.txt' So I'm guessing at a web.config at a parent level is already setting the MIME type for .txt.
Is there a way to set the MIME type for static content in a leaf directory (or for a specific directory) using a web.congig file?
I found it. You have to remove the other one before adding.
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".txt" />
<mimeMap fileExtension=".txt" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
We'd like to use IIS 7.5 output caching for an individual .aspx file, but after some reading at iis.net, it seems to me the caching can only be configured for various file extensions, but not for individual files. Is that correct or did I miss something?
Thank you.
Just change view to "content" select file, and config it. In extension add eq .js or .php. This config will be only to this file.
You can check this in:
eq
web.config
<location path="cachedfile.php">
<system.webServer>
<caching>
<profiles>
<add extension=".php" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="00:30:00" />
</profiles>
</caching>
</system.webServer>
</location>
I would like to set up rules in IIS7 for static content caching in my ASP.NET website.
I have seen these articles, which details how to do it using the <clientCache /> element in web.config:
Client Cache <clientCache> (IIS.NET)
Add Expires or Cache Control Header to static content in IIS (Stack Overflow)
However, this setting appears to apply globally to all static content. Is there a way to do this just for certain directories or extensions?
For example, I may have two directories which need separate cache settings:
/static/images
/content/pdfs
Is it possible to set up rules for sending cache headers (max-age, expires, etc) based on extensions and folder paths?
Please note, I must be able to do this via web.config because I don't have access to the IIS console.
You can set specific cache-headers for a whole folder in either your root web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Note the use of the 'location' tag to specify which
folder this applies to-->
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</location>
</configuration>
Or you can specify these in a web.config file in the content folder:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</configuration>
I'm not aware of a built in mechanism to target specific file types.
You can do it on a per file basis. Use the path attribute to include the filename
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="YourFileNameHere.xml">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
I had the same issue.For me the problem was how to configure a cache limit to images.And i came across this site which gave some insights to the procedure on how the issue can be handled.Hope it will be helpful for you too
Link:[https://varvy.com/pagespeed/cache-control.html]