Web Technology Asp - Net Unit V
Web Technology Asp - Net Unit V
When a browser asks for a page from a server, it is called a request. The Request object is used
to get information from a visitor. Its collections, properties, and methods are described below:
Collections
Collection Description
ClientCertificate Contains all the field values stored in the client certificate
Cookies Contains all the cookie values sent in a HTTP request
Contains all the form (input) values from a form that uses the post
Form
method
QueryString Contains all the variable values in a HTTP query string
ServerVariables Contains all the server variable values
Properties
Property Description
Returns the total number of bytes the client sent in the body of the
TotalBytes
request
Methods
Method Description
Retrieves the data sent to the server from the client as part of a post
BinaryRead
request and stores it in a safe array
Response Object
The ASP Response object is used to send output to the user from the server. Its collections,
properties, and methods are described below:
Collections
Collection Description
Sets a cookie value. If the cookie does not exist, it will be created, and
Cookies
take the value that is specified
Properties
Property Description
Buffer Specifies whether to buffer the page output or not
CacheControl Sets whether a proxy server can cache the output generated by ASP or
not
Appends the name of a character-set to the content-type header in the
Charset
Response object
ContentType Sets the HTTP content type for the Response object
Sets how long (in minutes) a page will be cached on a browser before it
Expires
expires
ExpiresAbsolute Sets a date and time when a page cached on a browser will expire
IsClientConnected Indicates if the client has disconnected from the server
Pics Appends a value to the PICS label response header
Status Specifies the value of the status line returned by the server
Methods
Method Description
AddHeader Adds a new HTTP header and a value to the HTTP response
AppendToLog Adds a string to the end of the server log entry
BinaryWrite Writes data directly to the output without any character conversion
Clear Clears any buffered HTML output
End Stops processing a script, and returns the current result
Flush Sends buffered HTML output immediately
Redirect Redirects the user to a different URL
Write Writes a specified string to the output
Example
The following simple example has a text box control where the user can enter name, a button to send
the information to the server, and a label control to display the URL of the client computer.
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
if (!String.IsNullOrEmpty(TextBox1.Text)) {
The page simply contains a DropDownList control, which automatically posts back each time a
new item is selected. It has 3 different colors, besides the default one, which is simply white.
Once a new item is selected, the ColorSelector_IndexChanged method is fired, from our
CodeBehind file:
using System;
using System.Data;
using System.Web;
Okay, two different parts to be explained here. First, the Page_Load method, which is called on
each page request. Here we check for a cookie to tell us which background color should be used.
If we find it, we set the value of our dropdown list to reflect this, as well as the background color
of the page, simply by accessing the style attribute of the body tag.
Then we have the ColorSelector_IndexChanged method, which is called each time the user
selects a new color. Here we set the background color of the page, and then we create a cookie,
to hold the value for us. We allow it to expire after one hour, and then we set it by calling the
SetCookie method on the Response object.
Try running the example, and set a color. Now close the browser, and start it up again. You will
see that the choice of color is saved, and it will remain saved for an hour. However, nothing
prevents you from saving the choice for much longer. Simply add a bigger value to the expiry
date, or set an absolute value for it.