HttpWebResponse.LastModified Property
Gets the last date and time that the contents of the response were modified.
Assembly: System (in System.dll)
| Exception | Condition |
|---|---|
| ObjectDisposedException | The current instance has been disposed. |
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 =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(myUri));
HttpWebResponse* myHttpWebResponse =
dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
if (myHttpWebResponse->StatusCode == HttpStatusCode::OK)
Console::WriteLine(S"\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(S"\nThe requested URI entity was modified today");
else
if (DateTime::Compare(today, myHttpWebResponse->LastModified) == 1)
Console::WriteLine(S"\nThe requested URI was last modified on: {0}",
__box(myHttpWebResponse->LastModified));
// Releases the resources of the response.
myHttpWebResponse->Close();
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.