Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2003, 09:11 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cookie btw. ASP and .NET

Hi,
In my asp page i have the following code:
<%
If Not Request.Form("Name") = "" Then
    Response.Cookies("Name") = Request.Form("Name")

end if
%>
<html>

In my aspx page i have the following:
Public Class COOKIES
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim NAME
NAME = Request.Cookies("Name")
Response.Write(NAME)

However the aspx doesn't seem to recognise the cookie. why?

Thanks


 
Old October 30th, 2003, 10:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

I know that ASP and ASP.NET implement different Session objects, and that you would need to write code to integrate the two. My guess is that that maybe the case for the cookies object too...

Brian
 
Old October 30th, 2003, 05:35 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Request.Cookies("cookieName") returns a System.Web.HttpCookie object.

You need to access the "Value" property of that object.

Request.Cookies("cookieName").Value

Peter
 
Old October 31st, 2003, 04:45 PM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for the reply. I add .value but it still doesn't work. Must i change anything in the web config file? Must i add any line in aspx.vb? Must I write the line before page.ispostback?

Thanks.

 
Old November 3rd, 2003, 11:23 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm stumped then.

Peter
----------------------------------------
Work smarter, not harder.
 
Old November 10th, 2003, 09:38 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the answer in MSDN (for some reason i can't find the link but here is something that i copied onto notepad):
In an earlier version of ASP, create a new ASP page, and then add the following code:
<%@ Language="VBScript"%>
<%
    Response.Cookies("MyCookie") = "some value and other characters such as #, $, and so on"
    Response.Cookies("MyCookie").Path = "/"
    Response.Write(Request.Cookies("MyCookie"))
%>
<body>
<form id="Form1" method="post" action="CookieTest.aspx">
    <input type="submit" value="Click Me" ID="Submit1" NAME="Submit1">
</form>
</body>

Create a new .aspx page named CookieTest.aspx in the same project or application.
Add the following code to the .aspx page:
<script runat="server" language="vb">
    sub Page_Load()
        Response.Write("Hello from CookieTest.aspx ...<br>")
        Response.Write(Request.Cookies("MyCookie").Value() + "<br>")
    end sub
</script>

Run the ASP page first. Take note of the output.
Click Submit1 to browse to CookieTest.aspx. Notice that the output is encoded in UrlEncode format. This occurs because the ASP code from the previous page sets the cookie's data.
To decode the data that is retrieved from the cookie, use the following syntax:
Response.Write(Server.UrlDecode(Request.Cookies("M yCookie").Value()))








Similar Threads
Thread Thread Starter Forum Replies Last Post
Diff btw Personlization and Membership Venkatachalam ASP.NET 2.0 Professional 0 February 1st, 2008 02:40 AM
Difference btw. Access 2000, 2003, 2007 marcusalan Access ASP 0 May 26th, 2007 02:41 AM
Cookie Updating in ASP.NET br_r14 Classic ASP Basics 1 May 5th, 2005 06:55 PM
Cookie Error when run web page test.aspx C#.net minhpx General .NET 1 August 10th, 2004 01:23 AM
Accessing .asp cookie from ASP.net ksams General .NET 4 July 7th, 2004 02:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.