Sideway
output.to from Sideway



Clent/Server Information



Draft for Information Only

Content

Request Object
 Request.Cookies Collection
   Syntax:
   Parameters:
   Remarks:
  Examples:

Request Object

Another function of Request object is the retrieving of HTTP client variables from the client.

Request.Cookies Collection

Request.Cookies Collection retrieves the the values of cookies which is sent in the HTTP request.

Syntax:

Request.Cookies(cookie)[(key)|.attribute]

 Or in an ASP file. Imply

<% Request.Cookies(cookie)[(key)|.attribute] %>

Parameters:

cookie

The parameter "cookie" is the name of the cookie in the Cookies collection to be retrieved. The data type of "cookie" is string and is enclosed by quotation marks (" ").

key

The optional parameter "key" is the name of the key of the parameter "cookie" to be retrieved. If the "key" is specifed, "cookie" is a dictionary and the retrieved is the value of the specified "key" from the dictionary "cookie The data type of "key" is string  and is enclosed by quotation marks (" ").

attribute

The parameter "attribute" is the optional information of the parameter "cookie" with delimeter ".". The values of attribute is

attribute value Description
HasKeys Read-only. To specify whether the cookie contains keys.

Remarks:

Cookies are transmitted as clear text in the HTTP header. Cookies are not suitable to store important data, such as login name and passwords. Besides, Cookies collection are only strings contained in an request headers. The values of Cookies collection can also be generated by any user. Therefore Cookie data in the HTTP header is not a secure way to identify a user. And header data or user input should be encoded or be validated before using.

The Cookies Collection is indexed by the names of the parameter "cookies" and its parameter "key" in the request Header. With the Request.Cookies Collection, the value of cookie can be retrieved by name or key. The value of a cookie can be retrieved by its "cookie" name. The value of the "key" of a "cookie dictionary can be retrieved by including the parameter "key" to the parameter "cookie".

For cookie without key, the Request.Cookies(cookie) will return the value of "cookie". For cookie with key, the Request.Cookies(cookie) will return as a single query string with all of the keys.

If no cookie is specified,  the Request.Cookies() will return as a single query string with the whole cookies collection.

The parameter "attribute" with value "HasKeys" is used to determine whether the specified cookie is a cookie dictionary or a cookie with key.

If two cookies of the same name are stored with different path attribute, for example. "/" and "/a", the HTTP request, "/a/ab/cookie.asp" will sent both cookies to the web server, but the Request.Cookiew would only returen the value with the deeper path structure, i.e. "/a"

Since the multiple values of cookie dictionary or cookies collection is in the form of an collection, the values of the keys of a cookie dictionary or the values of the cookie elements of a cookies collection should be retrieved using a for each element loop in order to get the name of the element.

Examples:

  • Response.Cookies with "cookienamea and (key1 = cvalue1 and  key2 = cvalue2)" and then redefine "cookienameb = cookievalue"

    ASP script command:

    <% Response.Cookies("cookienamea")("key1") = "cvalue1" %>
    <% Response.Cookies("cookienamea")("key2") = "cvalue2" %>
    <% Response.Cookies("cookienameb") = "cookievalue" %> 

    HTTP header response:: 

    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: cookienamea=key2=cvalue2&key1=cvalue1; path=/
    Set-Cookie: cookienameb=cookievalue; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • With no cookie specified in Request.Cookies

    ASP script command:

    <%= Request.Cookies & "<br />"  %>

    HTTP response output (Buffered):

    cookienamea=key2=cvalue2&key1=cvalue1;cookienameb=cookievalue<br />

    HTML web page ouput:

    cookienamea=key2=cvalue2&key1=cvalue1;cookienameb=cookievalue

  • With value "cookienamea" specified in Request.Cookies

    ASP script command:

    <%= Request.Cookies("cookienamea") & "<br />"  %>

    HTTP response output (Buffered):

    key2=cvalue2&key1=cvalue1<br />

    HTML web page ouput:

    key2=cvalue2&key1=cvalue1

  • With value "cookienameb" specified in Request.Cookies

    ASP script command:

    <%= Request.Cookies("cookienameb") & "<br />"  %>

    HTTP response output (Buffered):

    cookievalue<br />

    HTML web page ouput:

    cookievalue

  • Check with HasKeys

    ASP script command:

    <%= Request.Cookies("cookienamea").HasKeys & "<br />"  %>

    HTTP response output (Buffered):

    True<br />

    HTML web page ouput:

    True

  • Check with HasKeys

    ASP script command:

    <%= Request.Cookies("cookienameb").HasKeys & "<br />"  %>

    HTTP response output (Buffered):

    False<br />

    HTML web page ouput:

    False

  • Loop for all cookie elements in the cookies collection by item

    ASP script command:

    <%
    For Each item in Request.Cookies
    Response.Write item & ": "& Request.Cookies(item) & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    cookienameb: cookievalue<br />
    cookienamea: key2=cvalue2&key1=cvalue1<br />

    HTML web page ouput:

    cookienameb: cookievalue
    cookienamea: key2=cvalue2&key1=cvalue1

  • Loop for all keys in dictionary cookie by item

    ASP script command:

    <%
    For Each item in Request.Cookies("cookienamea")
    Response.Write item & ": "& Request.Cookies("cookienamea")(item) & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    key2: cvalue2<br />
    key1: cvalue1<br />

    HTML web page ouput:

    key2: cvalue2
    key1: cvalue1


©sideway
close

References

  1. Active Server Pages, http://msdn.microsoft.com/en-us/library/aa286483.aspx, updated 20Dec2012
  2. ASP Overview, http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx, updated 21Dec2012
  3. ASP Best Practices, http://technet.microsoft.com/en-us/library/cc939157.aspx, updated 15Apr2013
  4. ASP Built-in Objects, http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx, updated 20Dec2012
  5. Response Object, http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx, updated 20Dec2012
  6. Request Object, http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx, updated 20Dec2012
  7. Server Object (IIS), http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx, updated 20Dec2012
  8. Application Object (IIS), http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx, updated 20Dec2012
  9. Session Object (IIS), http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx, updated 20Dec2012
  10. ASPError Object, http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx, updated 20Dec2012
  11. ObjectContext Object (IIS), http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx, updated 20Dec2012
  12. Debugging Global.asa Files, http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx, updated 15Apr2013
  13. How to: Debug Global.asa files, http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx, updated 15Apr2013
  14. Calling COM Components from ASP Pages, http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx, updated 15Apr2013
  15. IIS ASP Scripting Reference, http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx, updated 15Apr2013
  16. ASP Keywords, http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx, updated 15Apr2013
  17. Creating Simple ASP Pages, http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx, updated 15Apr2013
  18. Including Files in ASP Applications, http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx, updated 15Apr2013
  19. ASP Overview, http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx, updated 15Apr2013
  20. FileSystemObject Object, http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx, updated 14Mayr2013
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx, ADO Object Model, updated 15Apr2013
  22. ADO Fundamentals, http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx, updated 14Mayr2013
close

ID: 120200019 Last Updated: 2/7/2012 Revision: 0 Ref:

IMAGE

Home (5)

Business

Management

HBR (3)

Information

Recreation

Hobbies (7)

Culture

Chinese (1097)

English (336)

Reference (66)

Computer

Hardware (149)

Software

Application (187)

Digitization (24)

Numeric (19)

Programming

Web (644)new

CSS (SC)

ASP.NET (SC)

Regular Expression (SC)

HTML

Knowledge Base

Common Color (SC)

Html Entity (Unicode) (SC)

Html 401 Special (SC)

OS (389)new

MS Windows

Windows10 (SC)

.NET Framework (SC)

DeskTop (7)

Knowledge

Mathematics

Formulas (8)

Number Theory (206)

Algebra (20)

Trigonometry (18)

Geometry (18)

Calculus (67)

Complex Analysis (21)

Engineering

Tables (8)

Mechanical

Mechanics (1)

Rigid Bodies

Statics (92)

Dynamics (37)

Fluid (5)

Fluid Kinematics (5)

Control

Process Control (1)

Acoustics (19)

FiniteElement (2)

Biology (1)

Geography (1)

Latest Updated Links

Copyright © 2000-2019 Sideway . All rights reserved Disclaimers last modified on 10 Feb 2019