aspnet

Programming with ASP.NET Programming with ASP.NET

Hà Đ ng H ng

ư

Objectives

• ASP.NET and the Microsoft® .NET Framework

– “Looking back...“ – Concepts and Architecture

• ASP.NET Application

– Models

• Using Visual Studio .NET

– Visual demos

L p trình v i ASP.NET ớ ậ 2

Objectives

• ASP.NET and the Microsoft® .NET Framework

– “Looking back...“ – Concepts and Architecture

• ASP.NET Application

– Models

• Using Visual Studio .NET

– Visual demos

L p trình v i ASP.NET ớ ậ 3

Looking Back: Active Server Pages

• What is ASP?

– Server-side scripting technology – Files containing HTML and scripting code – Access via HTTP requests – Scripting code is interpreted on server side

• What can I do with ASP?

– Easily and quickly create simple Web applications – Generate dynamic Web content – Client-side scripting for validation – Access COM components to extend functionality

• Databases

L p trình v i ASP.NET ớ ậ 4

What’s Wrong with That?

• Mixes layout (HTML) and logic (scripting code)

Interpreting ASP code leads to performance loss

• Uses scripting languages that are not strongly typed

– Microsoft JScript® – Microsoft Visual Basic® Scripting Edition (VBScript)

• Browser compatibility

• No real state management

– No state sharing across Web farms – State is lost when IIS fails

• Update files only when server is down

L p trình v i ASP.NET ớ ậ 5

ASP.NET Core Concepts

• Separate layout and business logic

• Use services provided by the .NET Framework

• Code is compiled the first time a page is requested

• State management

• Make use of programming languages

– Cross-language integration

• Update files while the server is running!

L p trình v i ASP.NET ớ ậ 6

Architecture

• The .NET Framework Architecture

• Web Application Model

• Class Hierarchy

• Advantages

L p trình v i ASP.NET ớ ậ 7

The .NET Framework Architecture

Microsoft .NET Framework

ASP.NET

Windows Forms

Web Forms Web Services

Services Framework

Base

Data

Debug

...

Common Language Runtime

System Services

L p trình v i ASP.NET ớ ậ 8

Web Application Model

Web Client

IIS

ASP.NET Applications

.NET Framework

Operating System

L p trình v i ASP.NET ớ ậ 9

Class Hierarchy 1/2

• Namespaces

– Hierarchically structured – Dot-syntax, grouping classes logically – Abstract base classes and class implementations

• You are free to implement your own

– Sample: System.Web.UI.WebControls.Button

namespace

class name

– How to use namespaces:

• Sample:

using MyAlias = System.Web.UI.WebControls

L p trình v i ASP.NET ớ ậ 10

Class Hierarchy 2/2

System.Object

System.Web.UI.Control

WebControl

System.Web.UI. WebControls

ListControl

Table

ListBox

Button

CheckBoxList

TextBox

...

...

L p trình v i ASP.NET ớ ậ 11

Advantages

• Execute more quickly

• On-the-fly updates of deployed Web app

• Access to the .NET Framework

• Many programming languages

• Server controls

• Built-in security

Integration with Microsoft ADO.NET

• Full support for XML, CSS

• Built-in features for caching, cultures…

L p trình v i ASP.NET ớ ậ 12

Objectives

• ASP.NET and the Microsoft® .NET Framework

– “Looking back...“ – Concepts and Architecture

• ASP.NET Application

– Models

• Using Visual Studio .NET

– Visual demos

L p trình v i ASP.NET ớ ậ 13

Parts of a Web Application

• Content

– Web Forms, HTML, images, audio, video, other data

• Program logic

– Executable files, scripts

• Configuration

– Web configuration file, Style sheets, IIS settings

L p trình v i ASP.NET ớ ậ 14

Parts of ASP.NET App

In a completed Web application, the executable portion of the Web form is stored in an executable (.dll) that runs on the server under the control of IIS.

L p trình v i ASP.NET ớ ậ 15

Application cycle

L p trình v i ASP.NET ớ ậ 16

Role of .NET Framework

L p trình v i ASP.NET ớ ậ 17

Objectives

• ASP.NET and the Microsoft® .NET Framework

– “Looking back...“ – Concepts and Architecture

• ASP.NET Application

– Models

• Using Visual Studio .NET

– Visual demos

L p trình v i ASP.NET ớ ậ 18

The Visual Studio .NET programming environment

• Start page

– contains various panes to make information easier to find and to help simplify some common tasks, such as opening a recent file

L p trình v i ASP.NET ớ ậ 19

The Visual Studio .NET programming environment

• Visual Studio .NET Windows: two types of

windows: – Document windows: display the content of your application: the forms, Web pages, and code

– Tool windows: display the components you use to

create your application.

• Controls

• database connections

• Classes

• properties

L p trình v i ASP.NET ớ ậ 20

The Visual Studio .NET programming environment

L p trình v i ASP.NET ớ ậ 21

The Visual Studio .NET programming environment

• Toolbox

L p trình v i ASP.NET ớ ậ 22

The Visual Studio .NET programming environment

• Solution Explorer

L p trình v i ASP.NET ớ ậ 23

Editing Web documents

• Editing HTML

• Editing code (VB.NET, C# …)

L p trình v i ASP.NET ớ ậ 24

Running a Project

• Toolbar: choosing Start from

the Debug menu

• Keyboard: F5.

ERROR ?? ?

L p trình v i ASP.NET ớ ậ 25

Results

• Cool webpage!

• Error webpage!

– Known error ->

Correct it

– Unknown error ->

Set breakpoint and Debug

L p trình v i ASP.NET ớ ậ 26

Getting Help

L p trình v i ASP.NET ớ ậ 27

Summary

• Web applications – run on a server, – processing user requests for pages and composing those pages using executable code and static resources on the server.

– Web applications can provide dynamic content based on

dynamic server resources, such as a database, and based on user inputs,

– ASP.NET Web applications are made up of content, an

executable, and configuration files.

L p trình v i ASP.NET ớ ậ 28

Summary

• The content of a Web application is presented through

Web forms. – use HTML components like conventional HTML pages; – they can also respond to user events such as mouse clicks.

• Assemblies

– The Web application' s executable is stored in a .dll file called

an assembly

– are compiled to an intermediate state – the final compilation is done by the CLR just before running the

application.

L p trình v i ASP.NET ớ ậ 29

Summary

• Visual Studio .NET Start page

– view current product information, to open new or existing

projects, to set user environment preferences, and to sign up for Web hosting services.

• Edit Web Forms pages and HTML pages:

– visually by using the Document window' s Design mode; edit them as text by using the Document window' s HTML mode.

• Set the Help language filter

– view code samples in a single programming language or in

multiple languages.

L p trình v i ASP.NET ớ ậ 30