|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Read/Write Cookie in a ModuleHow 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 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 -- Show quoteCo-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 > > > Hi,
Larry Rebich wrote: Show quote > How do I read and write a cookie in an ASP.Net module? Response is not a command. It's a property of the Page object. I suggest > > 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 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 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 -- Show quoteCo-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 > Hi,
Peter Bromberg [C# MVP] wrote: > Response is certainly a property of the Page class, but it is also a property Totally. My answer was referring to the OP's specific question, in which > of the current HttpContext, which does NOT require a Page to be present, and > which can be made available in HttpHandlers and HttpModules. > Peter 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 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 -- Show quoteCo-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 > Hi,
Peter Bromberg [C# MVP] wrote: Show quote > L, Oh, OK. I see what you mean. On my side, I wanted to explain to him why > 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 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 |
|||||||||||||||||||||||