響應http報文中的Date屬性與cookie到期時間的關係,

來源:互聯網
上載者:User

響應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
  1. Changed the system time to a future time (e.g. 11th May 2020)
  2. Browsed any site - verified the log file created in the new date/time
  3. Changed the system time to be correct (today's date and time)
  4. 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



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.