473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Read/Write Cookie in a Module

How do I read and write a cookie in an ASP.Net module?

I can get this code to work in an aspx.vb class but not in a regular VB
module:

Response.Cookies.Add(c)

Response is not a recognized command in the module. I've tried importing
System.Web into the module but that is not allowed.

What I'm trying to do is centralize cookie processing. Perhaps there is a
better way.

Cheers,
Larry Rebich
Aug 10 '06 #1
6 3859
Larry,
Have you tried using

HttpContext.Current.Response?

if this is not null, then your HttpModule has access to the current Context,
along with the Request, Response, Server, Session etc. objects.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Larry Rebich" wrote:
How do I read and write a cookie in an ASP.Net module?

I can get this code to work in an aspx.vb class but not in a regular VB
module:

Response.Cookies.Add(c)

Response is not a recognized command in the module. I've tried importing
System.Web into the module but that is not allowed.

What I'm trying to do is centralize cookie processing. Perhaps there is a
better way.

Cheers,
Larry Rebich
Aug 10 '06 #2
Hi,

Larry Rebich wrote:
How do I read and write a cookie in an ASP.Net module?

I can get this code to work in an aspx.vb class but not in a regular VB
module:

Response.Cookies.Add(c)

Response is not a recognized command in the module. I've tried importing
System.Web into the module but that is not allowed.

What I'm trying to do is centralize cookie processing. Perhaps there is a
better way.

Cheers,
Larry Rebich
Response is not a command. It's a property of the Page object. I suggest
that you take some time and study the object model of ASP.NET and
generally learn about object oriented programming in VB.NET. The words
you use (module, command) hint that you learned VB or VBA, and VB.NET is
a very different animal.

Enjoy,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 11 '06 #3
Response is certainly a property of the Page class, but it is also a property
of the current HttpContext, which does NOT require a Page to be present, and
which can be made available in HttpHandlers and HttpModules.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Laurent Bugnion" wrote:
Hi,

Larry Rebich wrote:
How do I read and write a cookie in an ASP.Net module?

I can get this code to work in an aspx.vb class but not in a regular VB
module:

Response.Cookies.Add(c)

Response is not a recognized command in the module. I've tried importing
System.Web into the module but that is not allowed.

What I'm trying to do is centralize cookie processing. Perhaps there is a
better way.

Cheers,
Larry Rebich

Response is not a command. It's a property of the Page object. I suggest
that you take some time and study the object model of ASP.NET and
generally learn about object oriented programming in VB.NET. The words
you use (module, command) hint that you learned VB or VBA, and VB.NET is
a very different animal.

Enjoy,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 12 '06 #4
Hi,

Peter Bromberg [C# MVP] wrote:
Response is certainly a property of the Page class, but it is also a property
of the current HttpContext, which does NOT require a Page to be present, and
which can be made available in HttpHandlers and HttpModules.
Peter
Totally. My answer was referring to the OP's specific question, in which
he states that his code runs in a ASPX.VB file.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 12 '06 #5
L,
This is what the OP stated:
"I can get this code to work in an aspx.vb class but not in a regular VB
module:

Response.Cookies.Add(c)"

I interpret this to mean that he is trying to get cookies in either a
non-page based class, or an HttpModule (he says he "can" get it working in an
aspx.vb class).
Hence, my clarifying post.
Cheers and good posting,

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Laurent Bugnion" wrote:
Hi,

Peter Bromberg [C# MVP] wrote:
Response is certainly a property of the Page class, but it is also a property
of the current HttpContext, which does NOT require a Page to be present, and
which can be made available in HttpHandlers and HttpModules.
Peter

Totally. My answer was referring to the OP's specific question, in which
he states that his code runs in a ASPX.VB file.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 12 '06 #6
Hi,

Peter Bromberg [C# MVP] wrote:
L,
This is what the OP stated:
"I can get this code to work in an aspx.vb class but not in a regular VB
module:

Response.Cookies.Add(c)"

I interpret this to mean that he is trying to get cookies in either a
non-page based class, or an HttpModule (he says he "can" get it working in an
aspx.vb class).
Hence, my clarifying post.
Cheers and good posting,

Peter
Oh, OK. I see what you mean. On my side, I wanted to explain to him why
it was working in the Page but not outside of it (because in the Page,
Response is a property) ;-)

Anyway, it's not that relevant to the topic, the main point being that
you cannot program ASP.NET like you used to program VB or VBA.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
How does one read and write the cookie expiration date. At the moment my code is returning a value BUT a garbled value: '//Write cookie... Response.Cookies("Propsect").Expires = Date() + 1 ...
1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
16
by: ben beroukhim | last post by:
I have huge number of legacy code which use standard files functions. I would like to pass a memory pointer rather than a FILE pointer. I am trying to use FILEs in the code to refer to memory...
1
by: Doogie | last post by:
Hi, I am having a problem reading a cookie that I can see is being created. I create the cookie in my global.aspx.vb page like so: Sub Session_Start(ByVal sender As Object, ByVal e As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.