と で DateTime.Now または DateTime.UtcNow を使用する必要がHttpCookie.Expires
ありHttpCachePolicy.SetExpires
ますか?
Cookie は「GMT」DateTime.Now.AddDays(3)
時刻を送信していますが、GMT+5 の場合に送信するとどうなるかわかりません。Expires HTTP header (sec 14.21)と同じです。
何を使えばいいですか?
と で DateTime.Now または DateTime.UtcNow を使用する必要がHttpCookie.Expires
ありHttpCachePolicy.SetExpires
ますか?
Cookie は「GMT」DateTime.Now.AddDays(3)
時刻を送信していますが、GMT+5 の場合に送信するとどうなるかわかりません。Expires HTTP header (sec 14.21)と同じです。
何を使えばいいですか?
It doesn't matter in this case.
Internally, the first thing .SetExpires
does is convert your supplied datetime into UTC, before setting it on the cookie.
Bear in mind, as long as your datetime consumer uses the DateTime class correctly, then the two are the same - it is just that one is "baselined" to UTC and the other isn't:
20110701T14:00:00-1:00 (British Summer Time)
and
20110701T13:00:00+0:00 (UTC)
represent exactly the same datetime, namely 1pm UTC.
As long as the consumer handles this correctly (which it seems to, having looked in reflector) then it makes no difference.
If you were taking this and passing it in as a time string, then of course, it may well make a difference, but not in this case.
You can see the effect with the following code (assuming you are not in UTC yourself - if you are - change your settings to test!). They both output the same datetime, once you've asked for it to be converted to UTC.
WriteDateTime(DateTime.Now);
WriteDateTime(DateTime.UtcNow);
public static void WriteDateTime(DateTime dateTime)
{
Console.WriteLine(dateTime.ToUniversalTime().ToLongTimeString());
}
Cookieに使用される時間標準であるため、 DateTime.UtcNow メソッドを使用する必要があります。UTC は GMT と同等です。
MSDNから: System.DateTime.UtcNow
協定世界時 (UTC) で表される、このコンピューターの現在の日付と時刻に設定された DateTime オブジェクトを取得します。
それらの間の説明については、これを参照してください。