Microsoft KB Archive/165862

= PRB: document.lastModified Property Is Unreadable with ASP =

Article ID: 165862

Article Last Modified on 5/2/2006

-

APPLIES TO


 * Microsoft Active Server Pages 4.0
 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q165862



We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 6.0 running on Microsoft Windows Server 2003. IIS 6.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:

http://www.microsoft.com/technet/security/prodtech/IIS.mspx



SYMPTOMS
The lastModified property that the Internet Explorer HTML scripting object model exposes indicates the date and time at which the sender believes the resource was last modified. When this property is referenced in a page that the Active Server Page (ASP) framework generates, the client browser displays an unreadable value.



CAUSE
The ASP framework does not include the Last-Modified response header in its response to the client.



RESOLUTION
According to RFC 1945, Hypertext Transfer Protocol 1.0 -- HTTP/1.0, Last-Modified is an entity header field, and entity header fields are optional. Internet Explorer 3.0 does not handle the absence of this header gracefully.

Active Server Pages provides the Response Intrinsic object. Use the Response.AddHeader method to add the Last-Modified header to the HTTP response.

According to the RFC, the user agent, Internet Explorer, expects times to be expressed in Greenwich Mean Time (GMT). Although Microsoft Visual Basic Scripting Edition (VBScript) does provide many date and time manipulation functions, it does not provide a function to return GMT or a function to return the current time zone offset from which GMT could be derived. The following example uses JScript on the server to append the Last-Modified response header to those provided by IIS and the Active Server Page Framework. Replace the contents of the page above with the following code: <%@ LANGUAGE=JSCRIPT %>

<%     // JSCRIPT automatically formats the string as specified // in RFC 1945, HTTP/1.0 // e.g. Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT theCurrentTime = new Date

// Convert the date to GMT. theUTCLastModifiedTime = theCurrentTime.toGMTString

// Inject the header into the HTTP response. Response.AddHeader("Last-modified", theUTCLastModifiedTime) %>

   document.write "Last Modified on " & document.lastModified    Save the ASP file on the server, and refresh the page in the client browser. The last modified date should now be displayed correctly.



STATUS
Microsoft has confirmed that this is a problem in Internet Explorer versions 3.0 and 3.01.



Steps to Reproduce Behavior
  Create a new ASP page named baddate.asp, and paste the following HTML code:   <SCRIPT LANGUAGE=VBSCRIPT> document.write "Last Modified on " & document.lastModified </SCRIPT> </BODY> </HTML>

</li> <li>Save baddate.asp in a directory that corresponds to a Virtual Root in IIS. Make sure that the Virtual Root has been granted Execute permissions in IIS.</li> <li>Start Internet Explorer, and type the following URL, which points to this page, in the Address box:

http:// /<vroot_name>/baddate.asp

</li> <li>Observe that the date appears to be corrupted.</li></ol>

<div class="references_section">