I would like to add code in a program that determines when a website was last updated. Ideally you would give the code a URL of a website and it would return a DateTime that the website was last updated. Is there a way to do this using .NET -- and do it
reliably?
Adapt the snippet at this link to get the last modified date -
http://forums.asp.net/p/1003561/1388671.aspx
The Javascript document.lastModified property returns the date and time the current document was last modified - http://www.w3schools.com/jsref/prop_doc_lastmodified.asp
However it only works in Internet Explorer and Firefox & with static web pages - http://classicasp.aspfaq.com/date-time-routines-manipulation/why-does-javascript-s-document-lastmodified-not-work-in-asp-files.html
This seems to bear out what you said. It gets the last modified DateTime for static web sites but not for dynamic web sites. I am using this function in a desktop VB.NET program.
Function GetDateTimeLastModified(ByVal requestUriString As String) As DateTime
Dim DateTime_LastModified As DateTime = DateTime.Now
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Try
request = CType(WebRequest.Create(requestUriString), HttpWebRequest)
' We don't actually need to download the file to get information about it.
request.Method = "HEAD"
response = CType(request.GetResponse(), HttpWebResponse)
DateTime_LastModified = response.LastModified
response.Close()
Return DateTime_LastModified
Catch
Return Nothing
End Try
Return Nothing
End Function
Gary Frank
Participant
919 Points
339 Posts
How to find out when a website was last updated?
Apr 06, 2010 02:25 PM|LINK
I would like to add code in a program that determines when a website was last updated. Ideally you would give the code a URL of a website and it would return a DateTime that the website was last updated. Is there a way to do this using .NET -- and do it reliably?
url last modified Last updated
Bruce L
All-Star
18102 Points
2841 Posts
Re: How to find out when a website was last updated?
Apr 06, 2010 05:17 PM|LINK
I have not heard of a built in feature that will do that for you.
You probably have to create something from scratch yourself.
http://www.discountASP.NET
mvark
Star
7617 Points
1104 Posts
Re: How to find out when a website was last updated?
Apr 07, 2010 09:06 AM|LINK
Adapt the snippet at this link to get the last modified date - http://forums.asp.net/p/1003561/1388671.aspx
The Javascript document.lastModified property returns the date and time the current document was last modified - http://www.w3schools.com/jsref/prop_doc_lastmodified.asp
However it only works in Internet Explorer and Firefox & with static web pages - http://classicasp.aspfaq.com/date-time-routines-manipulation/why-does-javascript-s-document-lastmodified-not-work-in-asp-files.html
Tech Tips, Tricks & Trivia (T4) | My Code Gallery
Gary Frank
Participant
919 Points
339 Posts
Re: How to find out when a website was last updated?
Apr 07, 2010 08:15 PM|LINK
This seems to bear out what you said. It gets the last modified DateTime for static web sites but not for dynamic web sites. I am using this function in a desktop VB.NET program.
Function GetDateTimeLastModified(ByVal requestUriString As String) As DateTime Dim DateTime_LastModified As DateTime = DateTime.Now Dim request As HttpWebRequest Dim response As HttpWebResponse Try request = CType(WebRequest.Create(requestUriString), HttpWebRequest) ' We don't actually need to download the file to get information about it. request.Method = "HEAD" response = CType(request.GetResponse(), HttpWebResponse) DateTime_LastModified = response.LastModified response.Close() Return DateTime_LastModified Catch Return Nothing End Try Return Nothing End Function