I've been dealing with this problem for the better part of two days now, and I'm tired of banging my head against the desk, so I'm hoping someone here can help me.
I have what should be an incredibly simple challenge - store an 8 - 12 digit string on a users PC in the form of a cookie when they fill out a simple form on my ASP.NET page (written in VB.NET with Visual Studio 2008).
I've looked into every conceivable way there is to set a cookie, and tried all of them, but seemingly nothing I do causes the cookie to be stored. I don't get any errors - the cookie file simply doesn't appear in the cookie directory on the client machine ("C:\Users\username\AppDat
okies", for example).
Here's a quick rundown of what I've already tried:
* Setting the cookie expiration date several years into the future
* Manually setting the domain of the cookie
* Creating the cookie through response.cookies("CookieNa
* Creating the cookie as an HttpCookie object, and assigning values to the object's properties, then adding it with Response.Cookies.Add(Cooki
* Verifying that other web sites on my test workstation can set and read cookies (using http://www.html-kit.com/tools/cookietester/
* Running the project both in debug mode on my locally run development server, AND publishing the web site to the final production server (just in case the localhost domain was causing an issue).
* Mercilessly piling over every line in my web.config for anything remotely related to cookies
No matter what I try, it's totally fruitless. I'm trying to read the cookie back with "If IsNothing(Response.Cookies
lue) Then RAK = Response.Cookies("RAK").Va
lue". But again, I'm not even seeing the file appear in the cookie directory on the machine, so I don't think the problem is that I'm reading it wrong, I think it's that its not ever being written.
I've included the function that is supposed to write my cookie (the commented out code is an example of one of the other methods I was trying). The RNR object is a reference to a web service I have linked in (which I have already verified is working). I know the code to write the cookie is getting hit, because I've set breakpoints on my Response.Cookie lines, and can see it getting to them. So I ask... what am I doing wrong???
P.S. - Ultimately, this page is going to be read from mobile phones (mostly Android phones, but possibly some iPhones as well), so if there are any gotcha's I should be aware of with cookies and mobile devices, please mention them. Although at this point I haven't even gotten that far.
Thanks in advance!
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
If txtRAK.Text <> "" Then
Dim RAK As String = txtRAK.Text
If RNR.isRakValid(RAK) Then
Response.Cookies("RAK").Value = RAK
Response.Cookies("RAK").Expires = DateTime.Now.AddYears(10)
Response.Cookies("RAK").Domain = "sub.mydomain.com" 'Altered for post to Internet'
'Dim cookieRAK As New HttpCookie("RAK")'
'cookieRAK.Expires = DateTime.Now.AddYears(10)'
lblInvalidRAK.Visible = False
lblInvalidRAK.Visible = True