p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_components thread: Cookies


Message #1 by Norberto Goussies <norberto.goussies@c...> on Wed, 21 Mar 2001 08:55:18 -0300
Hello,

	I'm writing a COM component in VC++ with ATL, and I want to write a

cookie to the client from component. Does anyone know how to do this?

Thanks.

Message #2 by "Peter Lanoie" <planoie@e...> on Wed, 21 Mar 2001 10:09:12 -0500
You need to Add a project reference to the ASP response object/class.  I

have not worked with this myself, but a quick look into VB yielded me this:



Look for an Available Reference of "Microsoft Active Server Pages Object

Library".  Select that as a Project Reference, then you can use the

following code.



Dim Response As ASPTypeLibrary.Response

Dim Request As ASPTypeLibrary.Request



Dim sMyCookie

Response.Cookies("MyCookie") = "CookieValue"

sMyCookie = Request.Cookies("MyCookie")



I would recommend not using the response object right in your component for

two reasons:

1) If you are testing it, I don't know how you test the response object, and

this might be difficult.

2) It adds a lot of overhead if all you want is the ability to write a few

cookies.



A different solution you might want to look into is to create a property in

you class that is a dictionary object (maybe named Cookies).  Then when you

need to create cookies in your class methods, you could just create a new

dictionary key/value pair.  Back in ASP, you can then loop through the

"Cookies" property (dictionary object) with a regular for each...loop with

the response.cookies code for each key/value. This way you have eliminated

the existence of the response object in your component, and might grant you

additional flexibility (maybe you want to do something else with that data).

If you know what cookies you are going to be creating, you could just

include a property in the class with the cookie value(s) you need to create,

then call that property in a ASP cookie assignment.



Good Luck,



Peter



-----Original Message-----

From: Norberto Goussies [mailto:norberto.goussies@c...]

Sent: Wednesday, March 21, 2001 6:55 AM

To: ASP components

Subject: [asp_components] Cookies





Hello,

	I'm writing a COM component in VC++ with ATL, and I want to write a

cookie to the client from component. Does anyone know how to do this?

Thanks.




  Return to Index