HttpWebResponse.LastModified Eigenschap

Definitie

Hiermee haalt u de laatste datum en tijd op waarop de inhoud van het antwoord is gewijzigd.

public:
 property DateTime LastModified { DateTime get(); };
public DateTime LastModified { get; }
member this.LastModified : DateTime
Public ReadOnly Property LastModified As DateTime

Waarde van eigenschap

Een DateTime met de datum en tijd waarop de inhoud van het antwoord is gewijzigd.

Uitzonderingen

Het huidige exemplaar is verwijderd.

Voorbeelden

In dit voorbeeld worden een HttpWebRequest en query's voor een antwoord gemaakt. In dit voorbeeld wordt vervolgens gecontroleerd of de aangevraagde entiteit op elk moment van vandaag is gewijzigd.

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

Opmerkingen

De LastModified eigenschap bevat de waarde van de Last-Modified header die met het antwoord is ontvangen. De datum en tijd worden verondersteld lokale tijd te zijn.

Van toepassing op