Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HttpWebResponse.LastModified Property

Gets the last date and time that the contents of the response were modified.

Namespace: System.Net
Assembly: System (in system.dll)

public DateTime LastModified { get; }
/** @property */
public DateTime get_LastModified ()

public function get LastModified () : DateTime

Not applicable.

Property Value

A DateTime that contains the date and time that the contents of the response were modified.
Exception typeCondition

ObjectDisposedException

The current instance has been disposed.

The LastModified property contains the value of the Last-Modified header received with the response. The date and time are assumed to be local time.

This example creates an HttpWebRequest and queries for a response. This example then checks whether the entity requested had been modified any time today.

Uri myUri = new Uri(url);
    // Creates an HttpWebRequest for the specified URL. 
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); 
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
    if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
        Console.WriteLine("\r\nRequest succeeded and the requested information is in the response , Description : {0}",
                            myHttpWebResponse.StatusDescription);
    DateTime today = DateTime.Now;
    // Uses the LastModified property to compare with today's date.
    if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 0)
        Console.WriteLine("\nThe requested URI entity was modified today");
    else
        if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 1)
            Console.WriteLine("\nThe requested URI was last modified on:{0}",
                                myHttpWebResponse.LastModified);
    // Releases the resources of the response.
    myHttpWebResponse.Close(); 

Uri myUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL. 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
    WebRequest.Create(myUri);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
    myHttpWebRequest.GetResponse();

if (myHttpWebResponse.get_StatusCode().Equals(HttpStatusCode.OK)) {
    Console.WriteLine("\r\nRequest succeeded and the requested "
        + "information is in the response , Description : {0}", 
        myHttpWebResponse.get_StatusDescription());
}
DateTime today = DateTime.get_Now();
// Uses the LastModified property to compare with today's date.
if (DateTime.Compare(today,
    myHttpWebResponse.get_LastModified()) == 0) {
    Console.WriteLine("\nThe requested URI entity was modified "
        + "today");
}
else {
    if (DateTime.Compare(today, 
        myHttpWebResponse.get_LastModified()) == 1) {
        Console.WriteLine("\nThe requested URI was last "
            + "modified on:{0}",
            myHttpWebResponse.get_LastModified());
    }
}

// Releases the resources of the response.
myHttpWebResponse.Close();

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.