Home All Groups Group Topic Archive Search About

Read/Write Cookie in a Module

Author
10 Aug 2006 8:12 PM
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

Author
10 Aug 2006 8:40 PM
Peter Bromberg [C# MVP]
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




Show quote
"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
>
>
>
Author
11 Aug 2006 12:41 PM
Laurent Bugnion
Hi,

Larry Rebich wrote:
Show quote
> 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
Author
12 Aug 2006 1:19 AM
Peter Bromberg [C# MVP]
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




Show quote
"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
>
Author
12 Aug 2006 12:34 PM
Laurent Bugnion
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
Author
12 Aug 2006 3:10 PM
Peter Bromberg [C# MVP]
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




Show quote
"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
>
Author
12 Aug 2006 9:45 PM
Laurent Bugnion
Hi,

Peter Bromberg [C# MVP] wrote:
Show quote
> 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

AddThis Social Bookmark Button