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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.