Freigeben über


HttpWebResponse.LastModified-Eigenschaft

Ruft das Datum und die Uhrzeit der letzten Änderung des Inhalts der Antwort ab.

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

Syntax

'Declaration
Public ReadOnly Property LastModified As DateTime
'Usage
Dim instance As HttpWebResponse
Dim value As DateTime

value = instance.LastModified
public DateTime LastModified { get; }
public:
property DateTime LastModified {
    DateTime get ();
}
/** @property */
public DateTime get_LastModified ()
public function get LastModified () : DateTime

Eigenschaftenwert

Eine DateTime mit dem Datum und der Uhrzeit der Änderung des Inhalts der Antwort.

Ausnahmen

Ausnahmetyp Bedingung

ObjectDisposedException

Die aktuelle Instanz wurde bereits verworfen.

Hinweise

Die LastModified-Eigenschaft enthält den Wert des mit der Antwort empfangenen Last-Modified-Headers. Es wird davon ausgegangen, dass dem Datum und der Uhrzeit die Ortszeit zugrunde liegt.

Beispiel

In diesem Beispiel wird eine HttpWebRequest erstellt und eine Antwort abgefragt. Dann wird geprüft, ob die angeforderte Entität heute geändert worden ist.

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

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

HttpWebResponse-Klasse
HttpWebResponse-Member
System.Net-Namespace