Last Modification Time of a Web Page

September 7th 2006 HTTP .NET Framework

The following code returns the time when a web resource was last modified:

static DateTime GetModificationTime(string url)  
{  
   WebRequest request = WebRequest.Create(url);  
   HttpWebResponse response = (HttpWebResponse) request.GetResponse();  
   DateTime lastModified = response.LastModified;  
   response.Close();  
   return lastModified;  
}

It's quite a simple piece of code actually and very similar to a sample in MSDN. But maybe it will be useful to someone since a member of my development team was convinced that there is just no way to get this information in .NET.

Get notified when a new blog post is published (usually every Friday):

If you're looking for online one-on-one mentorship on a related topic, you can find me on Codementor.
If you need a team of experienced software engineers to help you with a project, contact us at Razum.
Copyright
Creative Commons License