Skip to main content
.NET Framework Class Library
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)
Syntax
Public ReadOnly Property LastModified As DateTime
public DateTime LastModified { get; }
public:
property DateTime LastModified {
	DateTime get ();
}
member LastModified : DateTime

Property Value

Type: System..::.DateTime
A DateTime that contains the date and time that the contents of the response were modified.
Exceptions
ExceptionCondition
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.

Examples

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


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()


            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 = gcnew 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();

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.