Results 1 to 6 of 6

Thread: How to Send and Receive Cookies in ASP?

  1. #1
    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...|
    |===================|

  2. #2
    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.

  3. #3
    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#
    %>

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    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 :
    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 :
    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

  5. #5
    Join Date
    Oct 2005
    Posts
    2,394

    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>

  6. #6
    Join Date
    May 2008
    Posts
    2,302

    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>")
    %>

Similar Threads

  1. Replies: 10
    Last Post: 07-03-2012, 08:41 AM
  2. Can't send SMS in Nokia C7 but can receive.
    By Ryder Allen in forum Portable Devices
    Replies: 8
    Last Post: 29-11-2011, 03:46 PM
  3. Cannot send or receive SMS on Nokia N8
    By affection in forum Portable Devices
    Replies: 3
    Last Post: 15-02-2011, 06:11 AM
  4. Replies: 5
    Last Post: 20-03-2010, 05:44 AM
  5. I can receive email, but I can't send it!
    By Czack in forum Windows Vista Mail
    Replies: 3
    Last Post: 11-04-2008, 09:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •