Tutorials » AspNet tutorials »

Frequently used Methods and Properties of Request object

This article explains the frequently used Methods and Properties of Request object

Frequently used Methods and Properies of Request object


This method is used to write dynamic text to the web page. In old ASP days, this was the only way to generate dynamic text and display to the user.


The above code will generate the current time as text and display to the user. But note that the text will be displayed on the top of the page. There is no way you can specify the location and format the text.

If you want to move the location of the text, you may have to do something like below:

Response.Write("<table width=500>")
Response.Write("<td align=right>")

ASP.NET provides several web controls including the Label control which allow you to specify the exact location where you want the control to be displayed. Due to this, the Response.Write() method is not widely used now.


Cookies are used to store small pieces of information in the client computer. In ASP.NET, the Response object is used to send cookies to the client browser. If you select the 'Remember Me' option at the time of login, we use the following code to store your user id in a cookie in your computer. When you come back to this site later, we retrieve the user id from the Request and load your information automatically, without asking you to login again.

Response.Cookies("AspSpiderUserId").Value = "your user id"
Response.Cookies("AspSpiderUserId").Expires = DateTime.Now.AddDays(7)

We use the above code to store your user id in a cookie. The name of the cookie used is "AspSpiderUserId". The cookie will expire after 7 days. This means, if you come back to our site after 7 days, we will not remember you! So, come back often!

As you saw in the previous chapter, the Request object is used to retrieve the values from the cookie.

Dim cookie As System.Web.HttpCookie = Request.Cookies("AspSpiderUserId")
if cookie is nothing then
Response.write ("Cookie 'AspSpiderUserId' not found.")
Response.write ("Value of Cookie 'AspSpiderUserId': " & cookie.Value)
end if


This may be the most frequently used method of the Response object. Response.Redirect() is used to redirect user from one page to another page or website.


When the above line of code is executed, the page will be redirected to the login page. Let us see another example.

if (bStatus = True) then
end if

The above code redirects to error or success page according to the status of some operation performed. For example, when user try to login to the website, if the user name and password are correct, the page can be re directed to a welcome page. Otherwise, an error page can be displayed.

Next Chapter: Introduction to Session handling
Previous Chapter: ASP.NET Response object
More Chapters: ASP.NET Tutorials
More Tutorials: Tutorial Index

Top Contributors
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India