Read/Write Cookie in a Module

L

Larry Rebich

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
 
G

Guest

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
 
L

Laurent Bugnion

Hi,

Larry said:
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
 
L

Laurent Bugnion

Hi,
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
 
G

Guest

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
 
L

Laurent Bugnion

Hi,
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top