Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=120200006

Status / Redirect

Response Object

Another important function of Response object is the output of HTTP status 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.Status Property

Response.Status property sets the value of the status line of HTTP response before the HTTP headers returned by the server to the client.

Syntax:

Response.Status =[StatusDescription]

 Or in an ASP file. Imply

<% Response.Status=[StatusDescription] %>

Parameters:

StatusDescription

The parameter "StatusDescription" is the status code with a brief description. The data type of "StatusDescription" is string and is enclosed by quotation marks (" "). .

Class Code Description
1xx : Informational 100 Continue
101 Switching Protocols
2xx : Success 200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No content
205 Reset Content
206 Partial Content
3xx : Redirection 300 Multiple Choices
301 Moved Permanently
302 Found/Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
4xx : Client Error 400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Time-out
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Large
415 Unsupported Media Type
416 Requested range not satisfiable
417 Expectation Failed
5xx : Server Error 500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Server Unavailable
504 Gateway Time-out
505 HTTP Version not supported
extension-code xxx Reason-Phrase

Remarks:

The Response.Status property can be used to modify the status line as defined in the HTTP specification returned by the server to the client according to the needed.

The response HTTP status line may not be understanded by the HTTP application. But the clint should understand the class of status code, the first digit of the status code and any unrecognized status code is considered as being equivalent to the x00 status code of that class.

Examples:

  • Default value with No Response.Status

    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.Status with value "301 Moved Permanently" to modify the status line of HTTP header

    ASP script command:

    <% Response.Status="301 Moved Permanently" %>

    HTTP header response: 

    HTTP/1.1 301 Moved Permanently
    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.Status with value "201 Created"  to specify the status line of HTTP header together with new created URI specified by Location HTTP header for redirection used by client with automatic redirection capability.

    ASP script command:

    <% Response.Status="201 Created" %>
    <% Response.AddHeader "Location","../../../../../Newdefault.asp" %>

    HTTP header response: 

    HTTP/1.1 201 Created
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Location: ../../../../../Newdefault.asp
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

  • Response.Status with value "301 Moved Permanently"  to specify the status line of HTTP header together with new permanent URI specified by Location HTTP header for redirection used by client with automatic redirection capability.

    ASP script command:

    <% Response.Status="301 Moved Permanently" %>
    <% Response.AddHeader "Location","../../../../../Newdefault.asp" %>

    HTTP header response: 

    HTTP/1.1 301 Moved Permanently
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Location: ../../../../../Newdefault.asp
    Content-Length: 0
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

Response.Redirect Method

Response.Redirect Method redirects the HTTP request to "a specified URL" by sending a 302 moved HTTP header to the client.

Syntax:

Response.Redirect(
    URL
)

 Or in an ASP file. Imply

<% Response.Redirect "URL" %>

Parameters:

URL

The parameter "URL" is the new Uniform Resource Locator (URL) to redirect. The data type of "URL" is an full URL or string of virtual path, absolute path to a location on the server or relative path to the original URL and is enclosed by quotation marks (" ").

Return Values:

The method has no return value. 

Remarks:

The parameter "URL" can include a query string.

Older Web browsers might convert a POST request to a GET request during a redirection.

The Output Content of the original URL is ignored and a redirection header is sent to the client as specified by the Response.Redirect. And an automatic repsonse body content with the redirection link of URL is also generated for those client without automatic redirection capability.

Examples:

  • Default value with No Response.Redirect

    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.Redirect with value "../../../../../newpage.asp" to redirect the original URL to the specified URL

    ASP script command:

    <% Response.Redirect "../../../../../newpage.asp" %>

    HTTP header response: 

    HTTP/1.1 302 Object Moved
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET
    Loction: ../../../../../newpage.asp
    Content-Length: 148
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
    Cache-control: private

    HTTP response output: 

    <head><title>Object moved</title></head>
    <body><h1>Object Moved</h1>
    This object m ay be found <a HREF="../../../../../newpage.asp">here</a>.
    </body>

Previous Month  FEB  2012  Next Month
SMTWTFS
1234
567891011
12131415161718
19202122232425
26272829

Previous Month  MAY  2013  Next Month
SMTWTFS
1234
567891011
12131415161718
19202122232425
262728293031

Sideway BICK Blog

04/02


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013