Hi all,

I want to get a cookies value from one .aspx.vb page to another .aspx.vb page.but i can not get it.
i give the code bellow:
This is in:(webForm2.aspx.vb):in this page I set the Cookies value
webForm2.aspx.vb
(code):

Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
            Dim str2 As String
            Request.Cookies.Remove("userInfo")
            str2 = "myValue"
            Response.Cookies("userInfo")("userName") = str2
            Response.Cookies.Add(aCookie)
            Dim str5 As String = Server.HtmlEncode(Request.Cookies("userInfo")("userName"))
            Response.Redirect("webForm1.aspx")
        End Sub

I can not retrieve cookies value from another page :webpage1.aspx.vb:
webForm1.aspx.vb
(code):

If Not Request.Cookies("userInfo") Is Nothing Then
            Dim aCookie As HttpCookie = Request.Cookies("userInfo")
            Dim str As String = Server.HtmlEncode(Request.Cookies("userInfo")("userName"))
        End If

::: Here if condition is execute but the cookies value is "".
So, how can get cookies value ?

Thank you in advance.

Recommended Answers

All 3 Replies

Why do you need to store username in cookie? ASP.NET gives you Page.Identity.User.Name in every page automatically for you.

More on cookies here

More on authentication here

Identity.User.Name is only of value on a site with windows authentication enabled.

Have you tried using Session variables? They will be "Alive" for the length of the session.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.