Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to Send and Receive Cookies in ASP?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-02-2010
Member
 
Join Date: Aug 2006
Posts: 114
How to Send and Receive Cookies in ASP?
  

Hi friends,
I have recently started with the Active Server Pages (ASP). I know the purpose of the cookies. I have tried them to send and receive in Java. But I don't know how to Send and Receive Cookies in ASP? I have tried many different methods, but was not successful. Since, I am new to ASP, I request to all that please explain me considering the newbie. Some sample of coding would be really grateful. Hoping that someone would help me soon.!!

__________________
|===================|
|YAY if that made sense...|
|===================|
Reply With Quote
  #2  
Old 09-02-2010
Member
 
Join Date: Mar 2008
Posts: 349
Re: How to Send and Receive Cookies in ASP?

For identifying an user, a cookie is used. I think that you should know more about the cookie. Once, if you know the actual functions of cookie, then it might help you while designing the code. A small file that the server embeds on the user's computer can be called as cookie. Whenever, the same computer requests a page with a browser, it will have to send a cookie. You can create as well as retrieve cookie values, by using an ASP. The function of ASP sessions are also very much similar to cookie. Similarly like ASP Sessions, ASP Cookies are used to store information specific to a visitor of your website.
Reply With Quote
  #3  
Old 09-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: How to Create Cookies in ASP?

You should know how to create cookies in ASP.!! Since, you said that you are new, I think that creating a cookie is important for you. For creating a cookie the "Response.Cookies" command is used. You must keep in mind that you will have to write the Response.Cookies command before the <html> tag. You can see the following example :
Code:
<%
Response.Cookies("carname")="HondaCity"
%>
In the above example, I have created a cookie named "carname" and assigned the value "HondaCity" to it.
You can also set the date when you want the cookie to expire. I have explained the same thing in following code :
Code:
<%
Response.Cookies("carname")="HondaCity"
Response.Cookies("carname").Expires=#March 16,2010#
%>
Reply With Quote
  #4  
Old 09-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: How to Send and Receive Cookies in ASP?

I am assuming that you are clear with the cookies concept. You can use the response.cookies collection object for sending the cookies to the browser. I have provided you with the syntax and comments, so that it would be easy to understand you. The following is used to send a cookie :
Quote:
set c = response.Cookies
c.Item(place) = value 'Adding a value with a place.
c(place) = value 'Same as above - short-hand form
c.Add value, place 'Same as above
c.Remove(place) 'Removing a place and its value
Once you send the cookies, then the receiving cookies from the browser can be done using the request.Cookies collection object. Check the following for the same :
Quote:
set c = request.Cookies
value = c.Item(place) 'Returning the value of the specified item.
value = c(place) 'Same as above - short-hand form.
for each n in c 'Iterating by place
v = c(n)
next
Reply With Quote
  #5  
Old 09-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: How to Send and Receive Cookies in ASP?

If you want to read all the cookies, then you can check the following example :
Suppose the following are sent to the user by the server :
Code:
<%
Response.Cookies("Continent")="Asia"
Response.Cookies("user")("subcontinent")="China"
Response.Cookies("user")("country")="China"
Response.Cookies("user")("years")="25"
%>
If you want to send all information to the user, you can do that by following way :
HTML Code:
<html>
<body>

<%
dim x,y
for each x in Request.Cookies
  response.write("<p>")
  if Request.Cookies(x).HasKeys then
    for each y in Request.Cookies(x)
      response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
      response.write("<br />")
    next
  else
    Response.Write(x & "=" & Request.Cookies(x) & "<br />")
  end if
  response.write "</p>"
next
%>

</body>
</html>
Reply With Quote
  #6  
Old 10-02-2010
Member
 
Join Date: May 2008
Posts: 2,290
Re: How to Send and Receive Cookies in ASP?

I wold to tell you that, you can also add the parameters to a URL in ASP. You can use the below code for adding the parameters to URL :
Code:
<a href="addpara.asp?fname=Miyu&lname=Juin">Go to Add Parameters Page</a>
And retrieve the values in the "addpara.asp" file like the following code :
Code:
<%
fname=Request.querystring("fname")
lname=Request.querystring("lname")
response.write("<p>Welcome " & fname & " " & lname & "!</p>")
response.write("<p>This is my Web site!</p>")
%>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Send and Receive Cookies in ASP?"
Thread Thread Starter Forum Replies Last Post
Internet explorer 9 displays Cookies error message” IE9 works better when it is cookies enabled, please enable cookies” Bellare Technology & Internet 10 07-03-2012 08:41 AM
Can't send SMS in Nokia C7 but can receive. Ryder Allen Portable Devices 8 29-11-2011 03:46 PM
Cannot send or receive SMS on Nokia N8 affection Portable Devices 3 15-02-2011 06:11 AM
Troubleshooting error messages that receive while trying to send and receive mail in Outlook hatred Windows Software 5 20-03-2010 05:44 AM
I can receive email, but I can't send it! Czack Windows Vista Mail 3 11-04-2008 09:59 AM


All times are GMT +5.5. The time now is 12:35 PM.