Sideway
output.to from Sideway
Draft for Information Only

Content

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

Response Object

Another important function of Response object is the output of HTTP headers to the client. As part of the HTTP header, these types of response objects should be sent before sending any body content to the client.

Response.Cookies Collection

Response.Cookies collection adds or sets the value of a cookie. The specified cookie will be created, if the cookie does not exist. Or the value of specified cookie will be set.

Syntax:

Response.Cookies(cookie)[(key)|.attribute]=value

 Or in an ASP file. Imply

<% Response.Cookies(cookie)[(key)|.attribute]=value %>

Parameters:

cookie

The parameter "cookie" is the name of cookie. The data type of "cookie" is string and is enclosed by quotation marks (" "). .

key

The parameter "key" is the optional key of the parameter "cookie". If the "key" is specifed, "cookie" is a dictionary and the key is set to "value" 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 possible values of attribute are.

attribute value Description
Domain Write-only. To specify the cookie is sent only to requests to the specified domain
Expires Write-only. To specify the date on which the cookie expires so that the cookie may be stored by the client in the client's disk after the session ends. Otherwise the cookie expires when the session end or if the date of "Expires" attribute setting is before the current date.
HasKeys Read-only. To specify whether the cookie contains keys.
Path Write-only. To specify the cookie is sent only to requests to the specified path. If the "Path" attribute is not set, the default value is the application path.
Secure Write-only. To specify whether the cookie is secure or not.

Value

The parameter "Value" is the value assign to the "cookie", "key" or "attribute". The data type of "Value" is string and is enclosed by quotation marks (" ").

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.

If the same cookie name is reassigned in the same response, the later one will destroy the previous one. That is old value will be replaced by new value for the same cookie. And a cookie with key will be destroyed by a cookie without key or a cookie without key will be destroyed by a cookie with key.

Examples:

  • Default value with No Response.Cookies

    ASP script command:

    <%  %>

    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: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Cookies with cookiename = cookievalue

    ASP script command:

    <% Response.Cookies("cookiename") = "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: cookiename=cookievalue; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Cookies with cookiename and (key1 = cvalue1 and  key2 = cvalue2)

    ASP script command:

    <% Response.Cookies("cookiename")("key1") = "cvalue1" %>
    <% Response.Cookies("cookiename")("key2") = "cvalue2" %> 

    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: cookiename=key2=cvalue2&key1=cvalue1; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

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

    ASP script command:

    <% Response.Cookies("cookiename")("key1") = "cvalue1" %>
    <% Response.Cookies("cookiename")("key2") = "cvalue2" %>
    <% Response.Cookies("cookiename") = "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: cookiename=cookievalue; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

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

    ASP script command:

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

    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: cookiename=key2=cvalue2&key1=cvalue1; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Cookies with "cookiename and (key1 = cookievalue1 and  key2 = cookievalue2)" and then set  cookie "ckey" = Response.Cookies("cookiename").HasKeys

    ASP script command:

    <% Response.Cookies("cookiename")("key1") = "cvalue1" %>
    <% Response.Cookies("cookiename")("key2") = "cvalue2" %>
    <% Response.Cookies("ckey")=Response.Cookies("cookiename").HasKeys %> 

    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: ckey=True; path=/
    Set-Cookie: cookiename=key2=cvalue2&key1=cvalue1; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Cookies with "cookiename = cookievalue" and then set  cookie "ckey" = Response.Cookies("cookiename").HasKeys

    ASP script command:

    <% Response.Cookies("cookiename") = "cookievalue" %>
    <% Response.Cookies("ckey")=Response.Cookies("cookiename").HasKeys %> 

    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: ckey=False; path=/
    Set-Cookie: cookiename=cookievalue; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Cookies with "cookiename = cookievalue" and its attributes

    ASP script command:

    <% Response.Cookies("cookiename") = "cookievalue" %>
    <% Response.Cookies("cookiename").Domain="127.0.0.1" %>
    <% Response.Cookies("cookiename").Expires=#February 10, 2012# %>
    <% Response.Cookies("cookiename").Path="/" %>
    <% Response.Cookies.Secure=True %> 

    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: cookiename=cookievalue; expires=Thu, 09-Feb-2012 16:00:00 GMT; domain=127.0.0.1; path=/; secure
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Cookies with "cookiename  and key1 = cookievalue" and its attributes

    ASP script command:

    <% Response.Cookies("cookiename")("key1") = "cookievalue" %>
    <% Response.Cookies("cookiename").Domain="127.0.0.1" %>
    <% Response.Cookies("cookiename").Expires=#February 10, 2012# %>
    <% Response.Cookies("cookiename").Path="/" %>
    <% Response.Cookies.Secure=False %> 

    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: cookiename=key1=cookievalue; expires=Thu, 09-Feb-2012 16:00:00 GMT; domain=127.0.0.1; path=/
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private


©sideway

ID: 120200005 Last Updated: 2/3/2012 Revision: 0 Ref:

close

References

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

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339new

Travel 7new

Reference 79

Computer

Hardware 251

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 431

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

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

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019