ASP.Net - McGraw

Transcription

ASP.Net - McGraw
Programming the Web
Using ASP.Net
Chapter 1:
ASP.Net
Dave Mercer
McGraw-Hill/Irwin
© 2004 by The McGraw-Hill Companies, Inc. All rights reserved.
1-2
Objectives
1. Briefly explain where
Active Server Pages
(ASP) originated
2. Describe how ASP
works in a Web page
3. Understand how ASP
and ASP.Net differ
4. Download ASP.Net
executables on the
Microsoft site
5. Check your server to
see if ASP or ASP.Net
is loaded
6. Create a simple ASP
application manually
7. Run your ASP
application
8. Review VS.Net features
9. Create the basis for an
ASP.Net application from
a VB.Net template
10. Discuss the fundamental
file types for ASP.Net
applications
1-3
Web Applications, ASP, and
Active Server Pages.Net
• Active Server Pages.Net consists of:
– Microsoft’s Active Server Pages technology
– Microsoft’s .Net Framework technology
• The name ASP reflects how the technology
makes Web pages “active” via programming
running on the server.
• The .Net Framework technology is a
foundation for developing applications that
work well over the Internet.
1-4
What is ASP.NET?
• ASP.Net is a technology designed to simplify
the creation of dynamic Web applications and
XML Web Services.
• ASP.Net is Microsoft’s next generation of
Active Server Pages (ASP), which relies on
the .Net Framework.
• Neither ASP nor ASP.Net is a programming
language, but developers familiar with them
know that they are accessed via
programming language calls.
1-5
How ASP and ASP.Net are Processed
• In ASP, you can write code directly between
HTML or include HTML in your responses.
• In ASP.Net, you create the Web page part of
it in one file (very similar to a standard Web
page written using HTML), and in another file
(called the codebehind file) you write
programming code.
• This separation of the display from the
processing is one of the great improvements
of ASP.Net over ASP.
1-6
Sample ASP Code
To respond to user input, you might
write:
<html>
<head><title>My Web Page</title></head>
<body>
<% Response.Write "<b>Hello</b>" %>
</body>
</html>
1-7
Sample ASP Code with VBScript
This example accepts form input and
responds accordingly:
<%
If Request.Form("name") = "Jim" Then
Response.Write "Hello"
Else
Response.Write "Goodbye"
End If
%>
1-8
Web Application Development
1-9
Application Development:
Getting Started
• Applications, whether Windows or Web, do a
few basic functions: accept input, process
data, and produce output.
• Applications intended for use by humans
have a user interface, while applications
intended for use by machines have interfaces
that may be difficult for people to use.
• The primary considerations developers face
are size, speed, reliability, and security.
1-10
Application Development:
The Project Plan
• The first step in creating an application from
an idea is to build a project plan.
• For business applications, the project plan
should outline the background of the idea, the
business need, how it will integrate into
existing business processes, etc.
• The project plan should also contain a
proposed development solution.
• From that point the project plan is a working
document that may be modified.
1-11
Sample Business Application
• A company that sells cruise ship packages
could use a Web-based application that:
– Advertises available cruises to users
– Provides them an opportunity to register as a
group for specific cruises
– Accepts payments online
– Tracks the number of registered users in their
group
– Notifies users when they are eligible for discounts
1-12
Application Programming Tools
• While code can be written with simple text
editing tools, and a compiler may be required,
developing applications with only these tools
is no longer considered very efficient.
• For many years, application developers have
been relying more and more on specialized
application development tools.
• Tools include Integrated Development
Environments (IDEs), specialized source
code editors, debuggers, and template files.
1-13
What Does ASP.Net Do?
• ASP.Net isn’t a standalone application
program. By itself, ASP.Net is just part of the
.Net Framework.
• The objects in ASP.Net are available for use
in ASP.Net Web Applications. ASP.Net
includes a number of objects that simplify
user interactions across the Web, such as the
Request and Response objects.
• ASP.Net also includes a facility for writing
code that runs at the application level.
1-14
ASP.NET Objects
• There are quite a few objects in ASP.Net that
will be familiar to developers who’ve written
Web applications with ASP:
–
–
–
–
–
–
HttpRequest
HttpResponse
HttpContext
HttpServerUtility
HttpCookie
HttpBrowserCapabilities
1-15
Developing Web Applications
• Web applications follow a different
development and usage pathway than static
Web sites:
– The application developers incorporate elements
of the site’s design specifications into all the pages
the user sees.
– The server responds to user requests by running
code, connecting to databases, processing user
input, and creating responses containing HTML,
text, and graphics.
– What one user sees may be entirely different from
what another user sees.
1-16
Using ASP.Net Objects
• With ASP.Net objects, a working knowledge
of HTML, and some Visual Basic .Net
programming, we could create an application
that does the following:
– Check to see what browser the user is using
– Deliver a home page coded in HTML
– Set a cookie on the user’s browser that
distinguishes them from other users
– Capture values submitted by the user from an
HTML form (or from a link they clicked)
– Perform data processing functions.
1-17
The Relationship Between Computers,
Servers, and Applications
1-18
Hosting Web Applications
• A Web server’s hardware and software must
be very robust. Server computers often
contain multiple processors and a large
amount of RAM, as well as plenty of Hard
Disk Drive space.
• Sometimes servers have a RAID
(Redundant Array of Inexpensive Drives)
system for redundant data storage, and
sometimes the servers are grouped into
“server farms,” in which multiple servers
serve a single application.
1-19
Developing Web Applications
• Developers often use the language (or
languages) they are most familiar with to
write the processing logic for Web
applications.
• Languages such as VBScript (often used with
ASP), PHP and Perl, Visual Basic.Net and
C#, C++, and Python are commonly used to
build Web application programming logic.
• ASP.Net can be used in conjunction with
many of these languages.
1-20
VS.Net Features
• VS.Net contains visual tools that approximate
what your applications are going to look like
in use. You can use VS.Net to drag and drop
elements onto your application forms.
• You can also format, arrange, size, and align
elements on your forms with your mouse, and
change their properties in the Properties
Window.
• VS.Net also contains code editors suited to
specific types of code, such as HTML, XML,
VB.Net, and C#.
1-21
Opening VS.Net
1-22
VS.Net: The Options Dialog Box
1-23
VS.Net Without the Start Page
1-24
VS.Net: The File Menu
1-25
VS.Net: The Edit Menu
1-26
VS.Net: The Find in Files Dialog Box
1-27
VS.Net: The Look In Dialog Box
1-28
VS.Net: The View Menu
1-29
VS.Net: The Server Explorer
1-30
VS.Net: The Customize Toolbox
Dialog Box
1-31
VS.Net: The Add-In Manager
Dialog Box
1-32
VS.Net: The Customize Dialog Box
1-33
VS.Net: The Options Dialog Box
on the Environment Node
1-34
VS.Net Editors and Other Tools
• Because it is an Integrated Development
Environment (IDE), Visual Studio.Net
contains a number of editors and designers:
–
–
–
–
The Text and Code Editor
The HTML Designer
The XML Designer
Debugging Tools
• VS.Net also contains a number of powerful
tools for assisting with the debugging
process.
1-35
Creating an ASP.Net Web Application
in VS.Net
• A new application under development is
contained in a Solution. A Solution is simply
a file that serves as a reference point for all
the folders, files, and other resources making
up the application.
• Inside a Solution, individual chunks of
processing logic called Projects are
contained. Each project should be logically
self-sufficient, but what goes into a project is
up to you. Projects contain files and folders
related to the functionality they possess.
1-36
The ASP.Net Web Application Template
• When you create a new Project using the
Visual Basic Projects ASP.NET Web
Application template, several files and folders
are created automatically:
–
–
–
–
–
–
–
References
AssemblyInfo.vb
Global.asax
A VSDISCO file
Styles.css
Web.config
WebForm1.aspx
1-37
The End