1. 程式人生 > >ie 瀏覽器無法儲存cookie,且與域名包含了下劃線(_)有關係的問題

ie 瀏覽器無法儲存cookie,且與域名包含了下劃線(_)有關係的問題

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">首先見測試.很直接的一個現象</span>

本地機器搭建一個web服務,index.html就是以下內容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>IIS7</title>
</head>
<body>

<script>
document.cookie = 'test=' + Math.random();

if (document.cookie.indexOf('test=') <0) {
	alert('cookie lost,cookie is:' + document.cookie);
} else {
	alert('cookie success,cookieis:' +document.cookie);
}
</script>
</body>
</html>


開啟c:/windows/systems/drivers/etc/hosts

加入二組對應關係

127.0.0.1 a-b.oa.com

127.0.0.1 a_b.oa.com

使用ie開啟

a-b.oa.com和a_b.oa.com 

將會看到a_b.oa.com無法儲存cookie現象,

而a-b.oa.com卻正常.

使用chrome二個都正常.也就是說chrome對於_線沒有被影響;

見下圖




有人說,ie是按照LDH 規則辦事,就是不允許_線,只能使用英文,數字,中劃線;

http://tools.ietf.org/html/rfc3696#section-2