When a request is made by a client for a particular file, IIS uses the MIME map to determine the correct MIME type to tell a client it will be receiving. IIS contains a large list of default MIME types to use and will return a MIME type of "application/octet-stream" for any file extension that is not explicitly mapped.
Cache Disabling Techniques
- The easiest way to disable caching of a given MIME type is to create folders based on the types to disable and then set custom headers for those folders. For example, the following steps will disable caching of files in an images folder:
- Create a folder under your Wwwroot folder named Images.
- Open the Internet Services Manager (ISM).
- Locate the Images folder under your default Web site.
- Right-click the Images folder and select Properties.
- Select the HTTP Headers tab.
- Click Add in the Custom HTTP Headers section.
- Add a header named Cache-Control with a value of no-cache.
- Click ok to apply the changes.
- The following steps describe an unsupported method of tricking IIS using Windows Scripting Host (WSH) and Active Directory Service Interfaces (ADSI) into returning a "no-cache" header for a specific MIME type, in this case .gif files, for an entire Web server by modifying the IIS metabase.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
- Save the following WSH code in your %SystemDrive%\InetPub\AdminScripts folder as MimeChange.vbs:
' specify the extension and MIME type to work with
varMimeExt = ".gif"
' NOTE - this entry stores an extra HTTP header with the MIME information
' this "tricks" IIS into sending the extra cache control header
varMimeTyp = "image/gif" & vbCrLf & "Cache-Control: no-cache"
' create the ADSI object & current MIME map at that path
Set objMimeMap = GetObject("IIS://localhost/w3svc")
varMimeMap = objMimeMap.GetEx("MimeMap")
' get the MIME map count & set search status to false
intCount = UBound(varMimeMap) + 1
boolFound = False
' loop through MIME map searching for existing extension information
For intMimeMap = 0 to intCount - 1
If varMimeMap(intMimeMap).Extension = varMimeExt Then
boolFound = True
' if no extension information is found, create the new mapping
If boolFound = False Then
intMimeMap = intCount
ReDim Preserve varMimeMap(intMimeMap)
Set varMimeMap(intMimeMap) = CreateObject("MimeMap")
varMimeMap(intMimeMap).Extension = varMimeExt
' store the new information in the MIME map
varMimeMap(intMimeMap).MimeType = varMimeTyp
- Execute the following command to modify the metabase:CSCRIPT %SystemDrive%\InetPub\AdminScripts\MimeChange.vbs
Future requests for .gif files will now returned with the desired "no-cache" header.
ID d'article : 247389 - Dernière mise à jour : 19 juin 2014 - Révision : 1