ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC.

Slides:



Advertisements
Similar presentations
Maintaining State Between the Client and Server Internet Programming Using VBScript and JavaScript 9.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Session 13 Active Server Pages (ASP) Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Web App Development with ASP.NET. Introduction In this chapter, we introduce web-app development with Microsoft’s ASP.NET technology. Web-based apps create.
1 Chapter 12 Working With Access 2000 on the Internet.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
ASP.NET Programming with C# and SQL Server First Edition
CST JavaScript Validating Form Data with JavaScript.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Chapter 9 Web Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
Session Tracking Dr. Awad Khalil Computer Science & Engineering Department AUC.
JavaScript, Fourth Edition
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Creating Web Applications Using ASP.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
ASP.NET Controls. Slide 2 Lecture Overview Identify the types of controls supported by ASP.NET and the differences between them.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Chapter 6 Server-side Programming: Java Servlets
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
ASP.NET Part I Dr. Awad Khalil Computer Science Department AUC.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
National College of Science & Information Technology.
Chapter 5 Validating Form Data with JavaScript
Computing with C# and the .NET Framework
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information.
PHP-II.
Presentation transcript:

ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC

ASP.NET Content Introduction.NET Overview.NET Framework ASP (Active Server Pages).NET Setup JScript.NET A Simple ASP.NET Example Web Forms Session Tracking Cookies Session Tracking with HttpSessionState ASP.NET and XML Reading and Writing Text Files Connecting to a Database in ASP.NET Code-Behind Approach ASP.NET Web Services Web Resources

Objectives In this topic, you will learn: –To program ASP.NET pages using JScript.NET. –To understand how ASP.NET pages work. –To understand the differences between client-side scripting and server-side scripting. –To create Web services. –To use and manipulate XML files with ASP.NET. –To understand Web forms and code-behind files. –To be able to use session tracking in an ASP.NET application. –To use ActiveX Data Objects.NET (ADO.NET) to access a database.

Session Tracking Personalization Protection of privacy Cookies.NET’s HttpSessionState object Use of input form elements of type “hidden” URL rewriting

Personalization & Privacy  Personalization makes it possible for e-business to communicate effectively with their customers and also improve user’s ability to locate desired products and services.  e-business began to establish mechanisms by which they could personalize user’s browsing experience, tailoring content to individual users while enabling them to bypass irrelevant information.  Business achieve this level of service by tracking each customer’s movement through the Internet and combining the collected data with information provided by the customer, including billing information, personal preferences, interests and hobbies.  A trade-off exists, however, between personalized e- business service and protection of Privacy.  Whereas some consumers embrace the idea of tailored content, others fear that the tracking technologies will have adverse consequences on their lives.

Techniques of Session Tracking  To provide personalized service to consumers, e-business must be able to recognize clients when they request information from a site. The request/response model on which the Web operates is facilitated by HTTP. Unfortunately, HTTP is a stateless protocol – it does not support persistent connections that would enable Web servers to maintain state information regarding clients.  To help the server to distinguish among clients, a unique session ID is assigned to each client on the Internet.  The tracking of individual clients, known as session tracking, can be achieved in a number of ways:  Cookies, .NET HttpSessionState,  Use of input form elements of type “hidden”  URL rewriting

Cookies  A popular way to customize interactions with Web pages is via cookies.  A cookie is a text file stored by a Web site on an individual’s computer that allows the site to track the individual’s actions.  The user’s computer receives a cookie the first time the user visits the Web site; this cookie is then reactivated each time the user revisits the site.  The collected information is intended to be anonymous record containing data that are used to personalize the user’s future visits to the site.  In addition to identifying users, cookies can also indicate their shopping preferences. When a Web Form receives a request from a client, the Web Form could examine the cookie(s) it sent to the client during previous communications, identify the client’s preferences and immediately display products that are of interest to the client.

Cookies  Every HTTP -based interaction between a client and a server includes a header containing information either about the request (when the communication is from the client to the server) or about the response (when the communication is from the server to the client).  When a Web Form receives a request, the header includes information such as the request type (e.g., GET ) and any cookies that have been sent previously from the server to be stored on the client machine. When the server formulates its response, the header information includes any cookies the server wants to store on the client computer and other information, such as the MIME type of the response.  If the programmer of a cookie does not set an expiration date, the Web browser maintains the cookie for the duration of the browsing session. Otherwise, the Web browser maintains the cookie until the expiration date occurs.  When the browser requests a resource from a Web server, cookies previously sent to the client by that Web server are returned to the Web server as part of the request formulated by the browser.  Cookies are deleted when they expire. The expiration date of a cookie can be set in the cookie’s Expires property.

HttpCookie Properties

Outline cookie.aspx (1 of 2)

Outline cookie.aspx (2 of 2)

Session Tracking with HttpSessionState

 The next Web application demonstrates session tracking using the Class Library’s HttpSessionState.  Every Web Form includes an HttpSessionState object, which is accessible through property Session of class Page.  The example contains two pages.  In the first page, users select their favorite programming language from a group of radio buttons, then submit the HTML form to the Web server for processing.  Property Session : to manipulate the page HttpSessionState object. When the Web page is requested, an HttpSessionState object is created and assigned to the Page’s Session property. We often refer to property Session as the Session object.  The Web page then allows the user to select another programming language or to view the second page in the application, which lists recommended books pertaining to the programming language that the user selected previously.  When the user clicks the hyperlink, the HttpSessionState previously stored on the client is read and used to form the list of book recommendations.

Session Tracking with HttpSessionState  Line 2 of the first page imports the namespace System. Classes of related components provided by the.NET Framework are organized and grouped into namespaces.  An Import statement makes.NET classes readily available by allowing programmer to use a class name without specifying the namespace in front of it. To import namespaces in an.aspx file, we use Import directive with an attribute Namespace to specify the namespace to import.  The.aspx file contains four radio buttons (lines ) with values C#, C++, C, and Python. The user selects a programming language by clicking one of the radio buttons.  The page also contains a Submit button, which, when clicked, calls submitButton_Click event handler (lines 62-79) which stores the user selections in the Session object.  Like a cookie, an HttpSessionState object stores name-value pairs. In session terminology, these are called session items, and they are placed in HttpSessionState object by calling method Add. Line 77 calls Add to place the language and its coressponding recommended book’s ISBN number into the HttpSessionState object.

Session Tracking with HttpSessionState  One of the primary benefits of using HttpSessionState objects (rather than cookies) is that HttpSessionState objects can store objects of any type (not just strings) as attribute values.  After values are added to the HttpSessionState object, the application handles the postback (lines 28-57) in method Page_Load. Here we retrieve information about the current client\s session from the Session object’s properties and display this information in the Web page.  Property SessionID (line 53) contains the session’s unique ID. The first time a client connects to the Web server, a unique session ID is created for that client. When the client makes additional requests, the client’s session ID is compared with the session IDs in the Web server memory.  Property Timeout (line 56) specifies the maximum amount of time that an HttpSessionState object can be inactive before it is discarded.

Session Tracking with HttpSessionState  When the postback occurs, certain components are revealed (i.e., their Visible property is set to true ), whereas others become hidden (i.e., their Visible property is set to false ).  The welcome message is displayed (line 32), and two hyperlinks located toward the button of the page become visible (line 33-34). One link requests the current page (lines ), and one requests recommendations.aspx (lines ).  Note that clicking the first hyperlink (i.e., the one that requests the current page) does not cause a postback to occur. The file optionsPage.aspx is specified in the NavigateUrl property of the hyperlink. When the hyperlink is clicked, this page is requested as a completely new request to allow the user to select a new programming language.  After the postback, the form labels and elements are hidden (lines ).

Session Tracking with HttpSessionState  Line 17 defines books as a Hashtable, which is a data structure that stores key-value pairs.  A hash table is like an associative array in which keys are mapped to array positions that store values. The program uses the key to store and retrieve the associated value in the hash table. In this example, the keys are strings that contain the programming language names, and the values are strings that contain the ISBN numbers for the recommended books.  Class Hashtable provides method Add, which takes as arguments a key and a value. The value for a specific hash table entry can be obtained by indexing the hash table with the value’s key. For instance: books[ language ] ; in line 72 returns the value from the key- value pair in which language is a key in the books hash table.  Lines add four programming languages and their respective ISBNs to the Hashtable.

Session Tracking with HttpSessionState  Clicking the Submit button causes a postback to occur. As a result, the condition in the if statement (line 28) of the Page_load event handler evaluates to true, and lines execute.  Line 42 determines whether the user selected a language. If so, that language is displayed in welcomeLabel (line 49).  Additionally, clicking Submit causes submitButton_Click (lines 62-79) to be called. If the user selects a language, event handler submitButton_Click adds a key-value pair to the Session object specifying the language chosen and the ISBN number for a book on that language.  Next, a postback occurs.  Each time the user clicks Submit, submitButton_Click adds a new language-ISBN pair to the HttpSessionState object.  The user is then provided two links. The user can choose another language (i.e., return to the first page with the radio buttons) or link to recommendationsPage.aspx, which displays a list of book recommendations on the basis of the user’s language selections.

Session Tracking with HttpSessionState  The file recommendationsPage.aspx contains a label (lines 44-47) and a list box (lines 49-51).  The label displays the text Recommendations if the user has selected one or more languages; otherwise it displays NO Recommendations.  The ListBox Web control displays the recommendations created by the ASP.NET page’s script.  Evend handler OnInit (lines 15-38) retrieves the session information. OnInit is an event handler that is called when a page is initialized. If a user has never selected a languages during any visit to this site, the Session object’s Count property will be zero. This property indicates the number of session items contained in a Session object. If the Session object is null (i.e., no language has ever been selected), then we display the text No Recommendations.

Session Tracking with HttpSessionState  If the user has chosen a language, the for statement (lines 22-31) iterates through the Session object. The value in a key-value pair is retrieved from the Session object by indexing the Session object with the key name, using the same process by which we retrieved a value from our hash table.  We access the Keys property of class HttpSessionState (line 25), which returns an object that contains all the keys in the session. This line indexes our object (as if it were an array) using the current for loop’s control variable to retrieve the current key.  Lines add to ListBox a string formed by combining the KeyName’s value, the string “ How to Program. ISBN#: “ and the value from the Session object for which KeyName is the key.

Outline optionsPage.aspx (1 of 6)

Outline optionsPage.aspx (2 of 6)

Outline optionsPage.aspx (3 of 6)

Outline optionsPage.aspx (4 of 6)

Outline optionsPage.aspx (5 of 6)

Outline optionsPage.aspx (6 of 6)

Outline recommendationsPage.aspx (1 of 3)

Outline recommendationsPage.aspx (2 of 3)

Outline recommendationsPage.aspx (3 of 3)