4

I want to know how to get last modified date of the webpage using c#...?

I tried the below code but I get only date as today

HttpWebRequest req =(HttpWebRequest)WebRequest.Create("http://www.codeproject.com/KB/cs/youmanager.aspx");
HttpWebResponse res =(HttpWebResponse) req.GetResponse();
DateTime  abcd = res.LastModified;

Thanks in advance.

Bassie
  • 9,529
  • 8
  • 68
  • 159
Ajit
  • 309
  • 1
  • 3
  • 8
  • I don't see the problem. The page is reported as being last modified today, I'd assume since it's dynamically generated. Are you looking for a way to get the date `7 Jan 2011` (the date that the page was first posted)? – Matt Ball Jun 14 '11 at 03:52
  • Have you read this? http://stackoverflow.com/questions/5180826/how-to-retrive-last-modified-date-of-uploaded-file-in-asp-net – abramlimpin Jun 14 '11 at 03:52
  • @eibhrum uploaded file `!=` a web page. – Matt Ball Jun 14 '11 at 03:53
  • http://stackoverflow.com/questions/5180826/how-to-retrive-last-modified-date-of-uploaded-file-in-asp-net this will work for asp.net not in winforms – Ajit Jun 14 '11 at 03:54
  • 2
    Can you elaborate ..what do you mean by **last modified date of the webpage** – V4Vendetta Jun 14 '11 at 03:54
  • @v4vendetta In javascript there is function called document.lastmodified(). This will get the date which the webpage is edited or updated. – Ajit Jun 14 '11 at 03:57

1 Answers1

1

According to this your method should work. Maybe the page was actually modified today?

Also looking at this response here it is up to the HTTP server to set the Last-Modified response header. So if the server does not set the field correctly you can't rely on it.

Community
  • 1
  • 1
b3n
  • 3,805
  • 5
  • 31
  • 46
  • I saw those ... But as you can see I tried many many sites and I got the value as todays date. Is there any other method to access the information using Fileinfo or likethat – Ajit Jun 14 '11 at 04:06
  • http://www.codeproject.com/KB/cs/youmanager.aspx I wrote this article hence I know when I modified this page.. But I am not getting that date – Ajit Jun 14 '11 at 04:10
  • @Ajit last modified date in javascript is sourced out from the headers and i believe this information is not part of the headers by default in case of aspx page. (I think you won't be able to get the date also via javascript too) – V4Vendetta Jun 14 '11 at 04:13
  • as explained in the post above, if the server does not set it properly you wont get anything useful from the field. Have a look at your server's response with fiddler or firebug and see what the server sets for the Last-Modified response header. – b3n Jun 14 '11 at 04:22
  • 1
    It seems that if the server does not send the `Last-Modified` header, the `LastModified` property returns the current date whenever it is read. – alecov Feb 01 '14 at 19:39