Session Cookies blocked when Server Name is NOT DNS compliant
While I was trying to tackle the problem of blocked session cookies in our Web_Test server, I found something very important and very few people know so far:
According to Microsoft, after the latest patch of the Servers (or the Browsers):
Cookies on ASP pages are blocked if the server name contains characters that are not supported by Domain Name System (DNS). For example, you cannot use underscore characters (_) in the server name. This behavior is by design.
This fact happens to match our case on Web_Test, because we have ’_’ in server name! So no matter where you are, as long as you use http://Web_Test, or http://Web_Test.MyDomain.com, you will NOT be able to send the session cookies to the client to maintain the session (You still have other way to maintain session in ASP.NET, described later.) But if you use, say, http://192.168.1.77, or, if you are at the server. http://localhost, http://127.0.0.1, you will be OK.
This is NEW to me. I believe also new to many people who get confused why suddenly the session is not working any more!
Why do we have this rule, and when did this start to happen ? Microsoft just mentioned it is security related, and it is already happening.
So how do we solve our own problem with Web_Test ?
Well, the straightforward way is to rename it to, say, WebTest, or Web-Test. Actually, I added the following entry:
192.168.1.77 WebTest
to the hosts file of the machine where browser is at (I did that on MyServer.MyDomain-test.com), then browsed the web server by doing http://WebTest. it worked.
Another way, which is only available to ASP.NET, is to set cookieless = "true" in the following section of the web.config file:
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="true"
timeout="20"
/>
This is ASP.NET’s way to maintain session without cookies. It is quite useful, as more and more people turning off cookies because of security concern.
So, in the future, what kind of server name should we use, to comply with DNS naming convention ?
According to DNS, the characters should supports RFC 1123, which permits "A" to "Z", "a" to "z", "0" to "9", and the hyphen (-). The fully qualified domain name length should be no more than 63 bytes per label and 255 bytes total for an FQDN (Fully Qualified Domain Name)
For details, please refer to:
http://support.microsoft.com/default.aspx?scid=kb;en-us;325192
and
http://www.microsoft.com/resources/documentation/Windows/2000/server/reskit/en-us/cnet/cncf_imp_xvxz.asp
