Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 30th, 2003, 09:11 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old October 30th, 2003, 10:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
Reply With Quote
  #3 (permalink)  
Old October 30th, 2003, 05:35 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #4 (permalink)  
Old October 31st, 2003, 04:45 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
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.

Reply With Quote
  #5 (permalink)  
Old November 3rd, 2003, 11:23 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm stumped then.

Peter
----------------------------------------
Work smarter, not harder.
Reply With Quote
  #6 (permalink)  
Old November 10th, 2003, 09:38 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
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()))



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.