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 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.
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: http://127.0.0.1/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","http://127.0.0.1/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: http://127.0.0.1/Newdefault.asp
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: private
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 "http://127.0.0.1/newpage.asp" to
redirect the original URL to the specified URL
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: http://127.0.0.1/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="http://127.0.0.1/newpage.asp">here</a>.
</body>