HttpWebRequest.IfModifiedSince does not have a setter

How are we supposed to set the IfModifiedSince header on HttpWebRequest? It seems that it has no setter:

    using (var req = HttpWebRequest.Create(url) as HttpWebRequest)
        req.KeepAlive = false;
        req.HttpsAuthentCerts = certx509;
        req.ReadWriteTimeout = 2000;
        if (timestamp > DateTime.MinValue)
            req.IfModifiedSince = timestamp;  // <-- Compilation error here

The docs at HttpWebRequest.IfModifiedSince Property (System.Net) | Microsoft Learn show it working with a setter:

HttpWebRequest myHttpWebRequest= (HttpWebRequest)WebRequest.Create(myUri);
// Create a new 'DateTime' object.
DateTime targetDate = DateTime.Now;
// Set a target date of a week ago
myHttpWebRequest.IfModifiedSince = targetDate;

Bug or by-design?

I’m presuming this is a bug. Filed as HttpWebRequest.IfModifiedSince does not have a setter · Issue #511 · ghi-electronics/TinyCLR-Libraries · GitHub

1 Like

Fixed in pull request Implement setter for IfModifiedSince header by martincalsyn · Pull Request #514 · ghi-electronics/TinyCLR-Libraries · GitHub

1 Like


May I ask why you did not use the “standard” pattern ?

private string myDateToRFC1123String(DateTime d)

That said, both codes do not seem to return the same string :frowning: But I’m not an expert so I don’t know which one is correct. So you may be right :wink:


If that works in TinyCLR, then it’s much neater. I will test and if it works, will update the pull.

Yup - that works and is much cleaner. I didn’t know we had that format available so hat tip to @Bec_a_Fuel - thanks!

The PR has been updated.

1 Like

You’re welcome.