100 likes | 234 Views
ASP application. Combination of web pages files, handlers, modules and executable code that can be invoked from a virtual directory on a web server Contains: Aspx files: user interface + code Ascx files: user controls Global.asax: define global variables & react to global events
E N D
ASP application • Combination of web pages files, handlers, modules and executable code that can be invoked from a virtual directory on a web server • Contains: • Aspx files: user interface + code • Ascx files: user controls • Global.asax: define global variables & react to global events • Vb or cs files: code behind
Stages in ASP.NET request Web request IIS Is the file registered to ASP.NET? Handle the request internally or pass it to another service No Yes ASP.NET Has application instance been created? Instantiate the application, create Global variables and fire global events NO Yes Has the requested page been complied? Compile and cache page NO Yes Instantiate the page, fire page events and run event handling code Render page to HTML one control at a time Web response
Page Class properties • IsPostBack: Boolean showing if this is the first time the page is run • EnableViewState: Boolean to enable/disable maintaining page state • Controls: Collection of controls in the page • Request: reference to HttpRequest object (contains information about the current web request) • Response: Reference to HttpResponse object (set the web response) • Application and Session: Collections to hold information on the server
Page • Directives: set pre-processor options (processed before any code) • Post back is when the page calls itself again when the user interacts with a server control • The page and its content are sent to the server • To connect the code-behind file to ASP.NET user interface file, put attribute [Inherits=“class name”] and [src=“code-behind file name”] in the page directive
HttpRequest Class • All information related to a client request • When a form is submitted, data can be retrieved as collection • QueryString: collection of data passed using “Get” • Form: collection of data passed using “Post” method • Server variables: collection of Http headers • Browser: reference to HttpBrowserCapabilities object (type, version, platform, frames, cookies, tables, Javascript, vbscript, win32, ..) • Cookies: Collection of cookies • URL/ UrlReferrer
HttpResponse Class • Send information to the client • Write (string): Output to buffer • WriteFile (filename): Send file to client • Redirect (URL): Transfer user to another page • Cookies: Collection of cookies sent to client • BufferOutput: Bolean to collect the output in a buffer file before sending to client
Writing and Reading Cookies • Writing cookies: Dim c As HttpCookie c = New HttpCookie("writecookiefile") c("name") = "ahmed5667" c("id") = "123677" Response.Cookies.Add(c) c.Expires = DateTime.Now.AddMonths(2) • Reading cookies: Dim c As HttpCookie c = Request.Cookies("writecookiefile") TextBox1.Text = c("name") TextBox1.Text &= " " & c("id") OR For Each i In Request.Cookies Response.Write("<BR>" + i + "<BR>") Response.Write(Request.Cookies(i).Value) Next
Session & Application • Session: A collection object for every user accessing the application at a particular point of time. • SessionID: a unique number to identify each user • Application: One common collection object for all users and all web pages of the application
Application • Global events that apply to the whole application are stored in a file called Global.asax • Application start • Application Shutdown • Session Start • Session End • Application Error