Microsoft KB Archive/247389: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
(One intermediate revision by the same user not shown)
Line 51: Line 51:
== MORE INFORMATION ==
== MORE INFORMATION ==


MIME stands for &quot;Multipurpose Internet Mail Extensions,&quot; which refers to a way of configuring browsers or mail clients to view files that are in multiple formats based on a &quot;MIME type.&quot; &quot;MIME mapping&quot; is a process by which Internet Information Server (IIS) &quot;maps&quot; files by their extensions to a particular MIME type. For example, a file with the extension .htm has a MIME type of &quot;text/html&quot;, whereas a file with the extension .gif has a MIME Type of &quot;image/gif&quot;.<br />
MIME stands for "Multipurpose Internet Mail Extensions," which refers to a way of configuring browsers or mail clients to view files that are in multiple formats based on a "MIME type." "MIME mapping" is a process by which Internet Information Server (IIS) "maps" files by their extensions to a particular MIME type. For example, a file with the extension .htm has a MIME type of "text/html", whereas a file with the extension .gif has a MIME Type of "image/gif".<br />
<br />
<br />
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 &quot;application/octet-stream&quot; for any file extension that is not explicitly mapped.
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 ====
==== Cache Disabling Techniques ====


Line 72: Line 72:
When creating content, any files stored in this folder will no longer be cached. This is especially useful when working with images that are frequently updated.<br />
When creating content, any files stored in this folder will no longer be cached. This is especially useful when working with images that are frequently updated.<br />
</li>
</li>
<li>The following steps describe an ''unsupported'' method of tricking IIS using Windows Scripting Host (WSH) and Active Directory Service Interfaces (ADSI) into returning a &quot;no-cache&quot; header for a specific MIME type, in this case .gif files, for an entire Web server by modifying the IIS metabase.<br />
<li>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.<br />
<br />
<br />
<br />
<br />
Line 103: Line 103:


' specify the extension and MIME type to work with
' specify the extension and MIME type to work with
varMimeExt = &quot;.gif&quot;
varMimeExt = ".gif"
' NOTE - this entry stores an extra HTTP header with the MIME information
' NOTE - this entry stores an extra HTTP header with the MIME information
' this &quot;tricks&quot; IIS into sending the extra cache control header
' this "tricks" IIS into sending the extra cache control header
varMimeTyp = &quot;image/gif&quot; &amp; vbCrLf &amp; &quot;Cache-Control: no-cache&quot;
varMimeTyp = "image/gif" & vbCrLf & "Cache-Control: no-cache"


' create the ADSI object &amp; current MIME map at that path
' create the ADSI object & current MIME map at that path
Set objMimeMap = GetObject(&quot;IIS://localhost/w3svc&quot;)
Set objMimeMap = GetObject("IIS://localhost/w3svc")
varMimeMap = objMimeMap.GetEx(&quot;MimeMap&quot;)
varMimeMap = objMimeMap.GetEx("MimeMap")


' get the MIME map count &amp; set search status to false
' get the MIME map count & set search status to false
intCount = UBound(varMimeMap) + 1
intCount = UBound(varMimeMap) + 1
boolFound = False
boolFound = False
Line 128: Line 128:
   intMimeMap = intCount
   intMimeMap = intCount
   ReDim Preserve varMimeMap(intMimeMap)
   ReDim Preserve varMimeMap(intMimeMap)
   Set varMimeMap(intMimeMap) = CreateObject(&quot;MimeMap&quot;)
   Set varMimeMap(intMimeMap) = CreateObject("MimeMap")
   varMimeMap(intMimeMap).Extension = varMimeExt
   varMimeMap(intMimeMap).Extension = varMimeExt
End If
End If
Line 134: Line 134:
' store the new information in the MIME map
' store the new information in the MIME map
varMimeMap(intMimeMap).MimeType = varMimeTyp
varMimeMap(intMimeMap).MimeType = varMimeTyp
objMimeMap.PutEx 2,&quot;MimeMap&quot;,varMimeMap
objMimeMap.PutEx 2,"MimeMap",varMimeMap
objMimeMap.SetInfo
objMimeMap.SetInfo
                             </pre></li>
                             </pre></li>
<li>Execute the following command to modify the metabase:<span class="kbd userinput"> CSCRIPT %SystemDrive%\InetPub\AdminScripts\MimeChange.vbs</span><br />
<li>Execute the following command to modify the metabase:<span class="kbd userinput"> CSCRIPT %SystemDrive%\InetPub\AdminScripts\MimeChange.vbs</span><br />
<br />
<br />
Future requests for .gif files will now returned with the desired &quot;no-cache&quot; header.</li></ol>
Future requests for .gif files will now returned with the desired "no-cache" header.</li></ol>
</li></ul>
</li></ul>



Latest revision as of 13:50, 21 July 2020

Knowledge Base


Article ID: 247389

Article Last Modified on 11/23/2006



APPLIES TO

  • Microsoft Internet Information Services 5.0



This article was previously published under Q247389

SUMMARY

Web administrators may need to periodically disable the caching of content that changes frequently. This article describes a method to disable caching of document types.

MORE INFORMATION

MIME stands for "Multipurpose Internet Mail Extensions," which refers to a way of configuring browsers or mail clients to view files that are in multiple formats based on a "MIME type." "MIME mapping" is a process by which Internet Information Server (IIS) "maps" files by their extensions to a particular MIME type. For example, a file with the extension .htm has a MIME type of "text/html", whereas a file with the extension .gif has a MIME Type of "image/gif".

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:

    1. Create a folder under your Wwwroot folder named Images.
    2. Open the Internet Services Manager (ISM).
    3. Locate the Images folder under your default Web site.
    4. Right-click the Images folder and select Properties.
    5. Select the HTTP Headers tab.
    6. Click Add in the Custom HTTP Headers section.
    7. Add a header named Cache-Control with a value of no-cache.
    8. Click ok to apply the changes.

    When creating content, any files stored in this folder will no longer be cached. This is especially useful when working with images that are frequently updated.

  • 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.

    For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:



    1. Save the following WSH code in your %SystemDrive%\InetPub\AdminScripts folder as MimeChange.vbs:

      Option Explicit
      
      Dim boolFound
      Dim intCount
      Dim intMimeMap
      Dim objMimeMap
      Dim varMimeMap
      Dim varMimeExt
      Dim varMimeTyp
      
      ' 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
          Exit For
        End If
      Next
      
      ' 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
      End If
      
      ' store the new information in the MIME map
      varMimeMap(intMimeMap).MimeType = varMimeTyp
      objMimeMap.PutEx 2,"MimeMap",varMimeMap
      objMimeMap.SetInfo
                                  
    2. 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.


Keywords: kbhowto KB247389