0

Im setting a up a cookie value from server side in a button event as follows.

Private Sub btn_set_Click(sender As Object, e As EventArgs) Handles btn_set.Click
    Dim myCookie As HttpCookie = New HttpCookie("downloadToken", "sandeep")
    myCookie.Expires = Now.AddDays(1)
    myCookie.Secure = False
    myCookie.HttpOnly = True
    Response.Cookies.Add(myCookie)
End Sub

But when I check the value of downloadToken from clientside using JQUERY Cookie plugin, it returns undefined.

 Cookies.get("downloadToken"); //returns undefined

Immediately after Response.cookies.add, there is a file download code. That is actually sending file to the client for downloading.

 Response.AddHeader("Content-Disposition", "attachment; filename=" & FileInfo.Name)
 Response.AddHeader("Content-Length", FileInfo.Length.ToString())
 Response.AddHeader("Connection", "Keep-Alive")
 Response.ContentType = “application/octet-stream”
 Response.ContentEncoding = Encoding.UTF8
 Response.TransmitFile(FileInfo.FullName)
 Response.Flush()
 Response.End()

May I know Whats wrong in my code?

Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132
  • Possible duplicate of [Can't access cookies from document.cookie in JS, but browser shows cookies exist](http://stackoverflow.com/questions/17508027/cant-access-cookies-from-document-cookie-in-js-but-browser-shows-cookies-exist) – CodeCaster Feb 28 '17 at 11:36

1 Answers1

1

I was able to solve it. It was because Httponly is set to true.

I changed it

myCookie.HttpOnly = False

Now am getting the value in client side

Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132