473,786 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cookie s.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 3874
Larry,
Have you tried using

HttpContext.Cur rent.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.Cookie s.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.Cookie s.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.Cookie s.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.Cookie s.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.Cookie s.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
11065
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 '//Read cookie... ExpDate = Request.cookies("Propsect") Response.write "Prospect expiry date: " & expDate & "<br>"
1
2225
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 ASP: <% Response.Cookies("user")("firstname")="John" Response.Cookies("user")("lastname")="Smith"
16
3500
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 buffers. Basically, I want to be able to use all the standard read and write functions, but I want them to refer to memory locations, rather than disk files. I do not want to touch the legacy code. Does any one know of a library
1
1178
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 EventArgs) Dim user As String = Current.User.Identity.Name Dim roleCookieName As String = user & "-Roles" Dim rolesList As String = Response.Cookies(roleCookieName ).Value 'Only try to create the cookie if it is not already created.
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.