iis only Add Expires headers to images - iis

Add expires headers in iis is very Easy,but this cache all the static files. now i want only
add expires headers to images,how can i do that? even i want cached specific file?

put all your images in one folder
enter the manager--> yoursite--> images folder (or specific file)
right click--> HTTP HEADERs--> Set expire header/date ! --> APPLY/OK

I've been searching for a simpler solution and I found this.
Keep your static content inside a folder (eg: css, js). Create a web.config file inside that folder. Add these following lines. Here 7 is the number of days, change it as you desire.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
You are free to keep as many static content folder as you want, simply add this web.config file. Hope this helps.

Related

HTTP Header Remove/Change ETag after setup Cache-Control:no-cache

How to remove cached files in browser by server response?
I have accidentally setup
Cache-Control:no-cache
Then Lots of my client's browser cached javascript files. I have change the server http status and new response should have
Expire:0
Cache-Control:no-store
But the cached file does not get latest files. So I was reading some article and tried to remove/change ETag header and tried adding
<customHeaders>
<add name="ETag" value=" " />
</customHeaders>
But it does not work. I also tried to disable all cache from Output Caching in IIS.
But it does not work.
How can I make the browser gets latest files without doing by user side?
Thank you!
To Disable client cache in iis you could use the HTTP Response Headers feature:
1)Open iis manager, select your site.
2)Doble click HTTP Response Headers from the middle pane.
3)On the HTTP Response Headers page, in the Actions pane, click Set Common Headers.
4)In the Set Common HTTP Response Headers dialog box, select the Expire Web content check box and select one of the following options:
Select Immediately if you want the content to expire immediately after it is sent in a response.
Select After if you want the content to expire periodically. Then, in the corresponding boxes, type an integer and select a time interval at which content expires. For example, type 1 and select Days if you want the content to expire daily.
Select On (in Coordinated Universal Time (UTC)) if you want the content to expire on a specific day and at a specific time. Then, in the corresponding boxes, select a date and time at which the content expires.
If you have access to the source code mall modern browsers will treat resources such as a CSS, Javascript as new versions if you append a query string to them which is unique.
E.g
http://www.example.com/test.js?v=1.1
You can disable cache for specific file and folder by using the location tag:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Specific file -->
<location path="test.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
<!-- Folder including subfolders -->
<location path="folder/subfolder">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>

Remove duplicate files from IIS for same application

I have X the same applications in IIS(some code/exe, but different config file).
Would it be possible to put duplicate files to some folder?
For example I have applications:
Canada.weather.com
usa.weather.com
mexico.weather.com
Uses same .dll and .exe, but have different config.
As Lex says, we don't suggest you to put duplicate files to some folder. If one of the dll is missed or not, it will make all the sites down.
If you still want to do this , you could apply the setting in applicationHost.config and wrapping it in a tag.
The applicationhost.config file path :
%windir%\system32\inetsrv\config\applicationHost.config
Each sites will have its own location, you could add the custome configuration inside each location tag.
Like belowl, I enable the windows auth for "BrandoTestSite":
<location path="BrandoTestSite">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
Notice: This way is lower maintainability. We don't suggest you choose this way to manage mutiple application.

At what point in the run-time process does IIS compress output?

I recently tried to integrate WebMarkupMin, a run-time html minification library, into my site (C#, IIS 8, MVC 4). We have IIS compression enabled. I discovered that IIS actually compresses the action filter output stream, which means when I try to minify my html in an action filter, I am trying to minify already compressed content.
Question: At what point in the run-time process does IIS compress output? Is there any way to use mvc action filters to modify html ouptut without disabling IIS compression?
The IIS dynamic compression for ASP MVC output runs pretty late in the pipeline. In my test it was No. 315 out of 349 pipeline items and after all the asp.net modules ran.
To see the order of the executed modules in the IIS pipeline, set up Failed Request tracing (FREB) for your site and review the logs.
I would say there is no way in your MVC action filter to tell the compression module not to compress.
But you can turn compression off on a url basis:
In your web config use something like this:
<location path="my/long/route/">
<system.webServer>
<urlCompression doDynamicCompression="false" />
</system.webServer>
</location>
you are telling IIS to turn off dynamic compression for just that URL.
It is necessary assign to dynamicCompressionBeforeCache attribute a value equals to false:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
…
<system.webServer>
…
<httpCompression …>
…
</httpCompression>
<urlCompression … dynamicCompressionBeforeCache="false" />
…
</system.webServer>
…
</configuration>
I know this is an old issue but the error solved when I used UseResponseCompression before UseStaticFiles
app.UseResponseCompression();
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
OnPrepareResponse = context => context.Context.Response.Headers.Add("Cache-Control", "public, max-age=2592000")
});
app.UseWebMarkupMin();

web.config causes HTTP 500 issue with virtual directory in IIS

I'm fairly new to IIS so apologies if this is a basic question.
I have an IIS config serving an internal company website (php instead of asp.net). The prod version of the website is at the 'Default Web Site' level and I've got demo and test versions of the website mapped as virtual directories. The demo and test version are essentially copies of the prod directory. I've noticed the with the web.config copied to these VDs, I get an error 500 on the root url for the VD only. I.E. main website is https://mainwebsite.com and works fine but https://mainwebsite.com/demo/ doesn't work while https://mainwebsite.com/demo/index.php works fine.
The web.config file is pretty basic:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
</handlers>
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:03:00" />
</staticContent>
</system.webServer>
</configuration>
Moving the web.config file out of the way in the VD resolves the issue. Even though the files are identical, I wouldn't think that the file should cause a conflict as my understanding is that IIS supports multiple web config files.
Although I have a workaround in place by renaming or deleting the file, I am wondering if there's a way to keep the file in place without it causing this error.
Thanks to Panama Jack in the comments, I was able to resolve my issue.
I got this response with detailed errors:
Error Summary
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
And further down:
Config Error
Cannot add duplicate collection entry of type 'add' with unique key attribute 'value' set to 'index.php'
To resolve, I simply commented out this line in the web.config XML:
<add value="index.php" />
I'm sure there's a better way to approach this but for now, this gets me my answer and also how to get more info from IIS when the logs are not useful.
if you create a virtual directory to another web root
web.config will cause this (personally I think the location of this file is totally insane.. mixed with htm and images etc. )
Replicate the directory somewhere else without the web.config file/excluding it..then point the virtual directory there.. & have a task set up to copy newer files over..

IIS 7.5 How do you add a Dynamic HTTP Expires Header

In IIS 7.5, you can add static HTTP Response headers, but I want to add an "Expires" header that always specifies a date that is 7 days in the future.
I'm running php 5.4, so I'd like a solution that can do this by editing the web.config file rather than some c# code solution.
I know how to add the header using php, but that won't help for static image file's http headers (jpg, gif, png, etc).
The header should look something like this:
Expires: Thu, 31 May 2012 10:59:25 GMT
How can I make it dynamically always show a date and time 7 days in the future?
Edit:
Notice that I have the expires header that I want on my php files:
http://web-sniffer.net/?url=http%3A%2F%2Fwww.bestds.com
However, I'm not able to specify a date that is 7 days ahead for the "Expires" key on png files (for example), I'm having to use a static date far in the future:
http://web-sniffer.net/?url=http%3A%2F%2Fwww.bestds.com%2Fimage%2Ftlogo.png
This is a standard feature of IIS. The HTTP Response Headers module allows you to set this common header. This results in the following web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
You should do this only in the directories where you want this header to be send. Typically only directories with static content.
You can only add dynamic expires header using program code.
Source:
The Microsoft IIS Site
You should use Cache-Control max-age instead, like suggested in the other answer.

Resources