2

As documented here the LastModified property of the HttpWebResponse class:

contains the value of the Last-Modified header received with the response

Per a few other answers on here and other pages online (here for example):

It's completely up to the server if it sets the Last-Modified response header

If the server does not set this header, what should I expect the value of the property to be in .Net? DateTime.MinValue? DateTime.Now? Or is there some other way to detect if the server set this header?

Community
  • 1
  • 1
GoldieLocks
  • 845
  • 7
  • 22
  • `DateTime.Now` probably – Ehsan Sajjad Mar 03 '17 at 11:03
  • @EhsanSajjad I've added to my question - if that's the case, how can I tell the difference between the server sending me a LastModified of DateTime.Now, and .Net detecting a missing header and defaulting the property to DateTime.Now? – GoldieLocks Mar 03 '17 at 11:13

1 Answers1

1

If you look at the source code of HttpWebResponse you will see, that DateTime.Now is returned, if no Last-Modified header has been set by the server.

In order to determine, if a header value is present in the reponse, you can use the HttpWebResponse.GetResponseHeader method. E.g.

var isLastModifiedSent = !string.IsNullOrEmpty(webResponse.GetResponseHeader("Last-Modified"));
Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67