響應http報文中的Date屬性與cookie到期時間的關係,
今天在測試.net時,發現一個莫名其妙的問題:cookie老是儲存不到瀏覽器端;
經過仔細的比對成功與不成功的報文,竟然無意中發現好像Date與它有關係,這太讓我意想不到了,從來不知道cookie儲存還要考慮報文中的date
而不是cookie的到期日期設定即可,竟然它的到期時間基點是date,而非瀏覽器邊的客戶機器時間優先?
關於報文的date時間是cookie到期時間起算點的驗證代碼如下,php的
header('Date: Mon, 17 Mar 2015 05:34:54 GMT');//強制修改回應時間為當天的後一天,正常的時間點應該是當前
setcookie('a',rand(),time() + 3600);//cookie一個小時後才到期
這個代碼會發現cookie沒有被儲存在瀏覽器中,因為瀏覽器認為cookie相對date而言,已經到期了,所以沒有儲存,
但是按照我的理解,cookie起算點應該是客戶機的時間為準呀?
所以,確實不知http 屬性的date還有這樣的作用.
經過同事的努力,竟然發現這是iis的一個bug"上去了後,俺不想下來了";
來自http://serverfault.com/questions/217343/date-header-returned-by-iis7-is-wrong
This appears to be a known issue and frequently found on virtual machine due to time sync feature. You may need to restart HTTP service on IIS6 to recover the behavior. Please refer to the content below:
Problem Description
W3SVC logs show incorrect time - stuck on the same time 2007-11-04 04:56:06
REPRO STEPS
- Changed the system time to a future time (e.g. 11th May 2020)
- Browsed any site - verified the log file created in the new date/time
- Changed the system time to be correct (today's date and time)
- Now, browsed any website and saw that the time on the log files is now stuck on 11th May 2020's time
RESOLUTION
- net stop http
- net start w3svc
OR
- net stop http
- net start http
- iisreset
You must restart the http service whenever you change the date in the server.
Verified in the code and confirmed that this is by design and you need to follow the above steps to make IIS logging the correct time.
I hope the information helps.
Source: http://www.eggheadcafe.com/software/aspnet/31164622/wrong-date-and-time-in-iis-log-file.aspx