Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.

Similar presentations


Presentation on theme: "ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the."— Presentation transcript:

1 ASP.NET P AGE O BJECTS

2  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the server from the browser. Contains form and query data. Gets the HttpRequest object for the requested page.  RESPONSE: Writes HTML and other information back to the client browser. Gets the HttpResponse object associated with the Page. This object allows you to send HTTP response data to a client and contains information about that response.  SERVER: Provides server functionality for use in ASP. Gets the Server object, which is an instance of the HttpServerUtility class. Eg. using a database connection.  Global.asax and web.config are used for application control

3 Request  Gets the HttpRequest object for the requested page. Some properties:  ApplicationPath : Gets the ASP.NET application's virtual application root path on the server.  Browser : Gets information about the requesting client's browser capabilities.  ContentEncoding : Gets the character set of the entity-body.  Cookies : Gets a collection of cookies sent by the client.  FilePath : Gets the virtual path of the current request.  Files : Gets the collection of client-uploaded files (Multipart MIME format).  Form : Gets a collection of form variables.  Headers : Gets a collection of HTTP headers.

4  HttpMethod : Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.  IsAuthenticated : Gets a value indicating whether the user has been authenticated.  Params : Gets a combined collection of QueryString, Form, ServerVariables, and Cookies items.  Path : Gets the virtual path of the current request.  PhysicalPath : Gets the physical file system path corresponding to the requested URL.  QueryString : Gets the collection of HTTP query string variables.  RequestType : Gets or sets the HTTP data transfer method (GET or POST) used by the client.  ServerVariables : Gets a collection of Web server variables.  Url : Gets Information about the URL of the current request.

5 Request Eg. browsercheck Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = Request.Browser.Browser Label2.Text = Request.Browser.Version Label3.Text = Request.Browser.Platform Label4.Text = Request.Browser.Cookies End Sub

6 Response  Cookies : Gets the response cookie collection. Write a cookie.  Expires : Gets or sets the number of minutes before a page cached on a browser expires. If the user returns to the same page before it expires, the cached version is displayed. Expires is provided for compatibility with previous versions of ASP.  Clear() : Clears all content output from the buffer stream.  End() : Sends all currently buffered output to the client, stops execution of the page, and raises the Application_EndRequest event.  Redirect() : Overloaded. Redirects a client to a new URL. No HTML is allowed to have already be sent to the browser

7 Redirect example Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect(“http://www.google.com”) End Sub

8 Server  MachineName : Gets the server's computer name.  ScriptTimeout : Gets and sets the request time-out in seconds. Default = 90  HtmlDecode() : Decodes a string that has been encoded to eliminate invalid HTML characters.  HtmlEncode() : Encodes a string/special characters like to < and > to be displayed in a browser.  UrlDecode() : Decodes a string encoded for HTTP transmission and sent to the server in a URL.  UrlEncode() : Encodes a string for reliable HTTP transmission from the Web server to a client via the URL. Eg spaces are converted to + and special characters like & to %26  Transfer() : Server.Transfer is executed on the server. The page transferred to should be another Web Forms page (.aspx page) in the same application. You cannot use Server.Transfer to redirect to an.asp or.asmx page. Server.Transfer("WebForm2.aspx")

9 Server Example-birthday1 <% Dim Name As string Dim Age As string Age = "twenty three??" Name = " & " Age = Server.UrlEncode(Age) Name = Server.UrlEncode(Name) %> &name=<% Response.Write(Name)%>">click here

10 Server Example-birthday2 <% Dim Name As string Dim Age as string Name = Request.QueryString("Name") Age = Request.QueryString("Age") Name = Server.HtmlEncode(Name) Age = Server.HtmlEncode(Age) %> Happy Birthday May the next years be as good!

11 Global.asax  The Global.asax also known as the ASP.NET application file is located in the root directory of an ASP.NET application  This file contains code that is executed in response to application-level and session-level events raised by ASP.NET or by HTTP modules  You can also define objects with application-wide or session-wide scope in the Global.asax file  These events and objects declared in the Global.asax are applied to all resources in that web application  The Global.asax is an optional file. Use it only when there is a need for it  You can use this file to implement application security, as well as other tasks  The Global.asax file is configured so that any direct HTTP request(via. URL) is rejected automatically, so users cannot download or view its contents

12  The ASP.NET page framework recognizes automatically any changes that are made to the Global.asax file  The framework reboots the application, which includes closing all browser sessions, flushes all state information, and restarts the application domain  The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assign them to applications as needed  There are two set of methods that fire corresponding to the events  The first set which gets invoked on each request and the second set which does not get invoked on each request  Methods corresponding to events that fire on each request : Application_BeginRequest() – fired when a request for the web application comes in Application_AuthenticateRequest() – fired just before the user credentials are authenticated. You can specify your own authentication logic over here

13 Application_AuthorizeRequest() – fired on successful authentication of user’s credentials. You can use this method to give authorization rights to user. Application_ResolveRequestcache() – fired on successful completion of an authorization request Application_AcquireRequestState() – fired just before the session state is retrieved for the current request Application_PreRequestHandlerExecute() – fired before the page framework begins before executing an event handler to handle the request Application_PostRequestHandlerExecute() – fired after HTTP handler has executed the request Application_ReleaseRequestState() – fired before current state data kept in the session collection is serialized Application_UpdateRequestCache() – fired before information is added to output cache of the page

14 Application_EndRequest() – fired at the end of each request  Methods corresponding to events that do not fire on each request : Application_Start() – fired when the first resource is requested from the web server and the web application starts Session_Start() – fired when session starts on each new user requesting a page Application_Error() – fired when an error occurs Session_End() – fired when the session of the user ends Application_End() – fired when the web application ends Application_Disposed() – fired when the web application is destroyed

15 Web.Config  The web.config is an XML file, it can consist of any valid XML tags, but the root element should always be  Nested within this tag you can include various other tags to describe your settings  It simply holds keys and values recognized by ASP.NET  These values are easily modifiable and you can add your own custom key and values to control other settings  ASP.NET provides a hierarchical configuration system that is very extensible, so the settings you supply in each web.config file apply only to the directory that contains the file and those below it  To provide setting for your entire application, place this file in your root application folder  Like the global.asax file, ASP.NET also prevents the web.config file from being accessed via. a Web client

16  Changes to this file are automatically detected, and the application is automatically restarted for the new settings to take effect  No script blocks or HTML code, just pure XML  Inside the tags are two different elements: configuration section handlers and configuration section settings  The first section declares the types of data in the web.config file, and the second contains the actual key/value pairs of settings  Using the web.config is an ideal method of creating a robust application that can quickly adapt to changes in its environment  web.config exposes an element that can be used as a place to store application settings like connection strings, file paths etc.


Download ppt "ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the."

Similar presentations


Ads by Google