Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. How to access a cookie added by javascript from codebehind in c#

How to access a cookie added by javascript from codebehind in c#

Scheduled Pinned Locked Moved Web Development
csharpjavascripthtmlhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shaimmaa
    wrote on last edited by
    #1

    Hi the problem is I have an html page in which I add a cookie then it redirect me to a page out of my web application then return back from there to my web application again to an aspx page in which I am trying to access the cookie in Page_Load but it return null the code in html page: var date = new Date(); date.setHours(date.getHours() + 1); var x = date.getUTCDate(); document.cookie = "us=5555; expires=" + x.ToString + "; path=/"; the code in aspx page: Label3.Text = Request.Cookies["us"].ToString(); thanks

    M 1 Reply Last reply
    0
    • S Shaimmaa

      Hi the problem is I have an html page in which I add a cookie then it redirect me to a page out of my web application then return back from there to my web application again to an aspx page in which I am trying to access the cookie in Page_Load but it return null the code in html page: var date = new Date(); date.setHours(date.getHours() + 1); var x = date.getUTCDate(); document.cookie = "us=5555; expires=" + x.ToString + "; path=/"; the code in aspx page: Label3.Text = Request.Cookies["us"].ToString(); thanks

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      I have tested with two sample pages (Default.aspx and Default2.aspx). It is working fine.. the following is my code.. Default.aspx (HTML View) ------------------------ <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> Untitled Page function addCookie(){ var date = new Date(); date.setHours(date.getHours() + 1); var x = date.getUTCDate(); document.cookie = "us=5555; expires=" + x.ToString + "; path=/"; }

      HyperLink

      Default.aspx (Code View) ------------------------ Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Request.Cookies("us") IsNot Nothing Then Response.Write(Request.Cookies("us").Value) End If End Sub End Class Default2.aspx (Code View) ------------------------ <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> Untitled Page

      HyperLink

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups