Documente Academic
Documente Profesional
Documente Cultură
NET Objects
This article explains various objects used in ASP.NET programming.
We mentioned in come of the previous chapters that ASP.NET uses object oriented languages like C# or VB.NET. You can use any classes available in the .NET library to write robust programs. ASP.NET provides some Classes which make web development easier. Some of the classes used specifically for ASP.NET development are:
Take the first example - System.Web.HttpRequest. In the above example, HttpRequest is the name of the class, which is defined in the namespace System.Web In object oriented programming, if you want to create an object of a class, you may use a syntax like below: dim mySocket as Socket = new Socket() In the above example, we are creating an object ('mySocket') for the class 'Socket'. Similary, if you need to create an object of class 'System.Web.HttpRequest', it must be something like this:
dim request as System.Web.HttpRequest = new System.Web.HttpRequest() But the ASP.NET system has made your life easier. An object called 'Request' is already created for you, which is ready to use. You do not need to create an object for the class System.Web.HttpRequest. The name of the object is 'Request'. Similary, there are objects created by default for the other classes like HttpResponse, System.Web.SessionState.HttpSessionState and System.Web.ApplicationState. The name of objects are 'Response', 'Session' and 'Application' respectively. In one of the previous chapters, you learned how to display the current time using the Response.Write() method. 'Response' is the name of the object for the class 'HttpResponse' which is created by the system for you. That is why we could use 'Response.Write()' without creating an instance of the class 'HttpResponse'.
The above mentioned 4 objects are widely used in ASP.NET programming. It is important to learn these objects and their methods. You will learn more about these objects in the coming chapters.
What is in a Request ?
As you can think, a request obviously includes the URL which is requested. In addition to that, a Request includes several other information, including: 1. Details about the browser who makes the request (like version number, browser type etc) 2. Computer information like screen resolution, IP address of the user etc. 3. Cookies - the information stored in the client machine by the same web site. 4. Data inputted by the user (for example, when you register in a site, you are entering your registration details in the input fields. These details are sent to the server as part of the 'Request')
web request. An instance of this class is created by default in all the pages, so that you can use this object without creating again each time in all the pages. The name of this object is Request. In old ASP days, the Request object was the only way to retrieve the input data entered by the user in the input fields in the page. ASP.NET provides the event handling mechanism and web controls so that you can access user inputs in a more easy way.
If the tutorialId is invalid or a chapter not found for the corresponding tutorialid, this page will show an error. Request.Cookies Cooikes are used to store small pieces of information in the client computer. Many web sites store information like when did you visit their site last, your user name etc. When you login to a site and choose the option 'Remember my password', do you know how they remember your password? Your user name is stored in a cookie in your computer. For example, when you login to this site, if you choose the option 'Remember my password', we will save your user name into a cookie in your computer. If you come back to our site again later, we will
Dim cookie As System.Web.HttpCookie = Request.Cookies("AspSpiderUserId") if cookie is nothing then Response.write ("Cookie 'AspSpiderUserId' not found.") else Response.write ("Value of Cookie 'AspSpiderUserId': " & cookie.Value) end if
If the user name already exists in Cookie, we understand that you selected the option 'Remember my password' last time. So, we will not ask for your password again. We will automatically login you to the application. Many sites use Cookies to store more information like when did you visit their site last, what are the pages you visited etc. For example, if you go to an online shopping site and add few items to the shopping cart, they will store this information to the Cookies. When you come back to the same site again, those items will be automatically there in your Shopping cart because they had saved it in your computer cookie and put into your shopping cart when you came back to the site. Request.ServerVariables
This property can be used to extract specific information about the client who is making the request. For example, if you want to find the server IP address of the computer who is visiting your web page, use the following code:
dim ipAddress as string = Request.ServerVariables("REMOTE_HOST'") Response.Write ("Your IP Address is : " & ipAddress)
You can find which version of browser they are using to access your web site.
dim browser as string = Request.ServerVariables("HTTP_USER_AGENT'") Response.Write ("You are using this browser to access our web site: " & browser)
There are several server variables available to find more information from the Request. Try the following server side code in your web page:
dim str as string For Each str in Request.ServerVariables.AllKeys Response.write ("Key : '" & str & "' - Value '" & Request.ServerVariables(str) & "'") Next
What is a Response ?
In the web server world, a Response is exactly opposite to the Request. A 'Response' is the message sent from the web server to the client, when client makes a 'Request'. For each request from a client, the server gives a response, unless there is an error. When you type a URL in a web browser or when you click on a hyper link in any web page, your browser makes a 'Request' to the server for the specific URL. Then server process the request and send a response back.
ISAPI is a low level Win32 style API ISAPI is a low level unmanged Win32 API .asmx extension for Web Services
AdRotator The element <Impressions> has a number as a value. This number indicates how often the image is displayed with respect to other images. The more the value of the number in this element, the more is the frequency of the image that is displayed. The sum of all the impressions in the advertisement file should not exceed 2,047,999,999. Otherwise the AdRotator will throw an runtime exception.
Page file (.aspx) User control (.ascx) Web service (.asmx) Master page (.master) Site map (.sitemap) Website configuration file (.config)