Search | Contact | Link To Us  

      ASP.NET      

ASP.NET
Dev Environment
Web Forms
Web Controls
ADO .NET
Web User Controls
Deployment
XML Web Services
ASP.NET Feedback Form
Resources
Discussions
VB .NET
About



Advertisement





























     HomeASP.NETWeb Forms> Request, Response Objects 

Request, Response Objects

Request and Response objects represent information coming into the Web server from the browser and information going out from the server to the browser. The Request object is called the input object and the Response object is called the output object.

Response Object

As mentioned above, the Response object represents a valid HTTP response that was received from the server. The response header properties are read-only. Notable properties of the object are as follows:

Body: Gets the body of the HTTP response. Only the portion of the body stored in the response buffer is returned
BytesRecv: Gets the number of bytes the client received in the response
BytesSent: Gets the number of bytes send in the HTTP request
CodePage: Gets or sets the code page used for setting the body of the HTTP response
ContentLength: Gets the size, in bytes, of the response body
Headers: Gets a collection of headers in the response
HeaderSize: Gets the combined size, in bytes, of all the response headers
HTTPVersion: Gets the HTTP version used by the server for this response
Path: Gets the path that was requested
Port: Gets the server port used for the request
ResultCode: Gets the server's response status code
Server: Gets the name of the server that sent the response
TTFB: Gets the number of milliseconds that have passed before the first byte of the response was received
TTLB: Gets the number of milliseconds that passed before the last byte of the response was received
UseSSL: Checks whether the server and client used an SSL connection for the request and response

Sample Code

The following sample code assumes that you have a Button control and four RadioButtoin controls with a common GroupName property on a Web Form. The user will be sent to a new Web Page if he makes a selection from one of the radio button's and hits the Submit button. You can view the live demo at the bottom of this page.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles MyBase.Load

Dim ccc As String = "Response Object"
Response.Write(ccc)
Response.Write("Using Response object")
'using the response object's write method to write some text
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
Response.Redirect("http://www.google.com")
'using the response object's redirect method to redirect the user to another web page
ElseIf RadioButton2.Checked = True Then
Response.Redirect("http://www.amazon.com")
ElseIf RadioButton3.Checked = True Then
Response.Redirect("http://www.yahoo.com")
ElseIf RadioButton4.Checked = True Then
Response.Redirect("http://www.startvbdotnet.com")
End If
End Sub

Request Object

As mentioned above, the Request object represents an HTTP request before it has been sent to the server. Notable properties of this object are as follows:

Body: Gets/Sets the HTTP request body
CodePage: Gets/Sets the code page for the request body
EncodeBody: Gets/Sets whether ACT automatically URL encodes the request body
EncodeQueryAsUTF8: Gets/Sets whether ACT automatically UTF-8 encodes the request's query string
Headers: Gets the HTTP Headers collection object
HTTPVersion: Gets/Sets the HTTP version
Path: Gets/Sets the HTTP path
ResponseBufferSize: Gets/Sets the size of the buffer used to store the response body
Verb: Gets/Sets the HTTP method verb

Sample Code

Private Sub Page_Load(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles MyBase.Load

Dim s As String = Request.UserHostAddress()
'request's user's host address and writes using the response object's write method
Response.Write(s)

Dim a As String = Request.ApplicationPath()
'request's the application path
Response.Write(a)

Dim aa As String = Request.Browser.Browser
'request's the type of browser
Response.Write(aa)

Dim b As String = Request.CurrentExecutionFilePath
'request's the current execution path
Response.Write(b)

Dim c As String = Request.FilePath
'request's the path to the file that you are currently working with
Response.Write(c)

Dim cc As String = Request.HttpMethod
'gets the HttpMethod
Response.Write(cc)

If Request.Browser.Browser = "IE" Then
'checks to see if the browser is IE and if true displays a message
Response.Write("You are using IE")
Else
Response.Write("You are using some other browser")
End If

Response.Write("Your computer is/has the following" & Request.Useragent)
'displays the user information about his computer
End Sub

Live Code Demo


Response Object

Select your favourite Web site and hit the Submit button below

Request Object Demo

Hit the Button below to show me the Request Object code demo


  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2010 Startvbdotnet.com. All rights reserved.