HttpWebResponse.LastModified Property
Gets the last date and time that the contents of the response were modified.
[Visual Basic] Public ReadOnly Property LastModified As DateTime [C#] public DateTime LastModified {get;} [C++] public: __property DateTime get_LastModified(); [JScript] public function get LastModified() : DateTime;
Property Value
A DateTime containing the date and time the contents of the response were modified.
Exceptions
| Exception Type | Condition |
|---|---|
| ObjectDisposedException | The current instance has been disposed. |
Remarks
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.
Example
[Visual Basic, C#, C++] This example creates an HttpWebRequest and queries for a response. This example then checks if the entity requested had been modified any time today.
[Visual Basic] Dim myUri As New Uri(url) ' Creates an HttpWebRequest for the specified URL. Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest) Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse) If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "Request succeeded and the requested information is in the response , Description : {0}", myHttpWebResponse.StatusDescription) End If Dim today As DateTime = DateTime.Now ' Uses the LastModified property to compare with today's date. If DateTime.Compare(today, myHttpWebResponse.LastModified) = 0 Then Console.WriteLine(ControlChars.Cr + "The requested URI entity was modified today") Else If DateTime.Compare(today, myHttpWebResponse.LastModified) = 1 Then Console.WriteLine(ControlChars.Cr + "The requested Uri was last modified on:{0}", myHttpWebResponse.LastModified) End If End If ' Releases the resources of the response. myHttpWebResponse.Close() [C#] 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(); [C++] 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();
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace