0% found this document useful (0 votes)
20 views32 pages

Module 7: Building Web Applications

This document provides an overview of building web applications in ASP.NET. It discusses introducing ASP.NET, creating web form applications, building web services, and using web services. Specific topics covered include using response and request objects, maintaining client-side and server-side state, managing ASP.NET applications, an overview of ASP.NET security, and using global events. It also describes the structure of web forms, advantages of web server controls over HTML controls, and handling events in web forms applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views32 pages

Module 7: Building Web Applications

This document provides an overview of building web applications in ASP.NET. It discusses introducing ASP.NET, creating web form applications, building web services, and using web services. Specific topics covered include using response and request objects, maintaining client-side and server-side state, managing ASP.NET applications, an overview of ASP.NET security, and using global events. It also describes the structure of web forms, advantages of web server controls over HTML controls, and handling events in web forms applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 32

Module 7: Building Web

Applications
Overview

 Introduction to ASP.NET
 Creating Web Form Applications
 Building Web Services
 Using Web Services
 Introduction to ASP.NET

 Overview of ASP.NET
 Using Response and Request Objects
 Maintaining Client-Side State
 Maintaining Server-Side State
 Managing an ASP.NET Application
 Overview of ASP.NET Security
 Using Global Events with Global.asax
Overview of ASP.NET
 Code behind development
 Intuitive approach to development similar to Windows Forms
 Code can be compiled using any .NET-compatible language
 Significant performance improvement
 ASP.NET pages run side-by-side with ASP pages
 Files with the .aspx extension run side-by-side with current
ASP applications on IIS
 Automatic support for multiple browsers
 Rich DHTML, HTML 3.2, and small devices
 ASP.NET namespaces provide rich functionality
 Built-in support for Web Services
Using Response and Request Objects

 The System.Web namespace provides common Web


functionality
 Requesting information from the client
 Request object

Dim
Dim strValue
strValue As
As String
String == Request.Form("txtInput")
Request.Form("txtInput")

 Sending information to the client


 Response object
Response.Write("<H2>The
Response.Write("<H2>The date
date is:
is: "" && Now.Date
Now.Date && "</H2>")
"</H2>")
Maintaining Client-Side State

 Maintaining control state across multiple requests


 Set EnableViewState property of control
 Use the StateBag class to store extra data
ViewState("TempData")
ViewState("TempData") == 25
25

 Send data to client as hidden string


<input
<input type="hidden"
type="hidden" name="__VIEWSTATE"
name="__VIEWSTATE" value="dO…NnU="
value="dO…NnU=" />
/>

 Using cookies for enhanced client-side state


Response.Cookies("User_FullName").Value
Response.Cookies("User_FullName").Value == strFullName
strFullName
……
strFullName
strFullName == Request.Cookies("User_FullName").Value
Request.Cookies("User_FullName").Value
Maintaining Server-Side State

 Application object maintains application-level state


 Data for use by all users
Application("App_StartTime")
Application("App_StartTime") == Now
Now

 Session object maintains session-level state


 Data for use by a single client browser
 Data recoverable by means of Windows Service or SQL
Server database
Session("Session_StartTime")
Session("Session_StartTime") == Now
Now
Managing an ASP.NET Application

 Configuring ASP.NET applications


 XML configuration file – Web.config
 Human-readable and writeable
 Stored with the application
 Deploying ASP.NET applications
 XCOPY the pages, components, and configuration
 No registration required
 Updating ASP.NET applications
 Copy new files over old files
 No update utility, restart, or reboot required
 Live update keeps applications running
Overview of ASP.NET Security

 Security settings stored in web.config file


 Out-of-box authentication support
 Windows authentication – Basic, Digest, or Integrated
 Microsoft Passport authentication
 Forms (Cookie) authentication
 Role-based security architecture
Using Global Events with Global.asax

 Useful for initializing data for application or session state

Sub
Sub Application_Start(ByVal
Application_Start(ByVal Sender
Sender As
As Object,
Object, ByVal
ByVal ee As
As EventArgs)
EventArgs)
Application("SessionCounter")
Application("SessionCounter") == 00
End
End Sub
Sub
Sub
Sub Session_Start(ByVal
Session_Start(ByVal Sender
Sender As
As Object,
Object, ByVal
ByVal ee As
As EventArgs)
EventArgs)
Application("SessionCounter")
Application("SessionCounter") == Application("SessionCounter")
Application("SessionCounter") ++ 11
Session("StartTime")
Session("StartTime") == Now
Now
End
End Sub
Sub
Sub
Sub Session_End(ByVal
Session_End(ByVal Sender
Sender As
As Object,
Object, ByVal
ByVal ee As
As EventArgs)
EventArgs)
Application("SessionCounter")
Application("SessionCounter") == Application("SessionCounter")
Application("SessionCounter") -- 11
End
End Sub
Sub
 Creating Web Form Applications

 Structure of Web Forms


 Using HTML Controls
 Advantages of Web Server Controls
 Using Web Server Controls
 Handling Events
Structure of Web Forms

 Web Forms separate declarative tags from logic


 The .aspx file contains HTML and other tags
 The code-behind file contains logic and event handling

<tags> code

Logon.aspx Logon.aspx.vb
Using HTML Controls

 Direct relationship to preexisting HTML tags


 Client side by default
 Server side with runat=server directive
 Properties correspond one-to-one with HTML, weakly
typed
 Defined with HTML tag
<input
<input type=text
type=text id="text1"
id="text1" value="some
value="some text"
text" runat="server">
runat="server">

 ASP.NET includes HTML controls for commonly used HTML


elements
Advantages of Web Server Controls

 Automatic browser detection


 Detect capabilities of client and render accordingly
 Strongly typed, consistent object model
 Enables compile-time type checking
 Declared with XML tags
 Server side only using runat=server directive
<asp:textbox
<asp:textbox id="text2"
id="text2" text="some
text="some text"
text" runat="server">
runat="server">
</asp:textbox>
</asp:textbox>

 Rich functionality
 Example: Calendar or RadioButtonList control
Using Web Server Controls

 Intrinsic controls
 List controls for repetition
 Validation controls validate input
 Rich controls simplify common
Web page requirements
Handling Events

 Event handlers contain code for user interactions


 Page events: Init, Load, PreRender, UnLoad
Private
Private Sub
Sub Page_Load(ByVal
Page_Load(ByVal Sender
Sender As
As System.Object,
System.Object, __
ByVal
ByVal ee As
As System.EventArgs)
System.EventArgs) Handles
Handles MyBase.Load
MyBase.Load
If
If Not
Not IsPostBack
IsPostBack Then
Then 'IsPostBack
'IsPostBack is
is also
also available
available via
via 'Me'
'Me'
'Perform
'Perform action
action first
first time
time page
page is
is displayed
displayed
End
End If
If
End
End Sub
Sub

 Control events: Click, Changed, PreRender


Private
Private Sub
Sub btn_Click(ByVal
btn_Click(ByVal sender
sender As
As System.Object,
System.Object, __
ByVal
ByVal ee As
As System.EventArgs)
System.EventArgs) Handles
Handles btn.Click
btn.Click
btn.Text
btn.Text == "clicked"
"clicked"
End
End Sub
Sub
Demonstration: Creating Web Forms
Lab 7.1: Creating the Customer Logon Web Forms
 Building Web Services

 What Are Web Services?


 Creating a Web Service
 Enabling Web Service Discovery
 Deploying and Publishing a Web Service
What Are Web Services?

 Components accessible by means of the Internet rather than distributed COM

 Built using open Internet protocols XML,


XML,XSD,
XSD,HTTP,
HTTP,SMTP
SMTP
 Consumers send and receive SOAP
XML messages SOAP
 Defined in terms of the message order and Web
WebServices
Services
format Description
DescriptionLanguage
Language
 Site offers a description of the Web Discovery
Services it offers DiscoveryDocument
Document
 Search for a site that offers a Web Service UDDI
with a given capability UDDI
Creating a Web Service

1. Add a Web Service module to the project


 The .asmx file contains WebService directive
<%@
<%@ WebService
WebService Language="vb"
Language="vb" Codebehind="User.asmx.vb"
Codebehind="User.asmx.vb"
Class="WebApp.User"%>
Class="WebApp.User"%>

2. Create a Web Service description


3. Add public subroutines or functions to .asmx.vb file
 Add WebMethod attribute to procedure definitions
<WebMethod()>
<WebMethod()> Public
Public Function
Function AddUser(…)
AddUser(…) AsAs String
String
'Functionality
'Functionality to
to add
add aa user
user and
and return
return new
new ID
ID
Return
Return strNewId
strNewId
End
End Function
Function
Enabling Web Service Discovery
 Discovery document
 Enables location and interrogation of Web Service
descriptions
 Contains links to resources that describe services
 Stores information in XML format
 Created manually or dynamically
<?xml
<?xml version="1.0"
version="1.0" ?>
?>
<discovery
<discovery xmlns="http://schemas.xmlsoap.org/disco/"
xmlns="http://schemas.xmlsoap.org/disco/" ...>
...>
<contractRef
<contractRef ref="http://www.nwtraders.msft/Shopping/User.asmx?wsdl"
ref="http://www.nwtraders.msft/Shopping/User.asmx?wsdl"
docRef="http://www.nwtraders.msft/Shopping/User.asmx"
docRef="http://www.nwtraders.msft/Shopping/User.asmx"
xmlns="http://schemas.xmlsoap.org/disco/wsdl/"
xmlns="http://schemas.xmlsoap.org/disco/wsdl/" />
/>
...
...
</discovery>
</discovery>
Deploying and Publishing a Web Service

 Deploying a Web Service


 Copy .asmx, Web.config, and any components to an IIS
virtual directory
 Publishing a Web Service
 The discovery document is copied to IIS virtual directory
 Dynamic discovery document produced by ASP.NET
generates information for all services in all subfolders
 Manually created discovery document returns only
explicitly defined information
Demonstration: Creating a Web Service
 Using Web Services

 Exploring Web Services


 Invoking a Web Service from a Browser
 Invoking a Web Service from a Client
Exploring Web Services

 HTML description page


 Describes Web Service methods and arguments
 Provides simple test utility for methods
 Displays additional descriptions from attributes
 Appears when you enter Web Service URL
http://webservername/virtualdirectory/webservice.asmx
http://webservername/virtualdirectory/webservice.asmx

 WSDL describes methods, arguments, and responses


 Generated by using Web Service URL with ?WSDL
switch
Invoking a Web Service from a Browser

 Enter the URL for the Web Service with parameters


 Syntax:
http://webservername/vdir/webservicename.asmx/
MethodName?parameter=value
 Example:
http://www.nwtraders.msft/Shopping/User.asmx/AddUser?strName=Joe
http://www.nwtraders.msft/Shopping/User.asmx/AddUser?strName=Joe
Invoking a Web Service from a Client

 Visual Basic .NET creates a proxy class for early binding


 Steps required:
1. Add a Web reference
2. Enter the URL for the .asmx file
3. Create client code that uses appropriate namespaces

Sub
Sub btnSubmit_Click(…)
btnSubmit_Click(…) Handles
Handles btnSubmit.Click
btnSubmit.Click
Dim
Dim usr
usr As
As New
New Services.User()
Services.User() 'Services
'Services is
is the
the given
given namespace
namespace
MessageBox.Show(usr.AddUser(txtName.Text))
MessageBox.Show(usr.AddUser(txtName.Text))
End
End Sub
Sub
Demonstration: Using a Web Service
Multimedia: How Web Services Work
Lab 7.2: Creating and Using the CustomerService Web
Service
Review

 Introduction to ASP.NET
 Creating Web Form Applications
 Building Web Services
 Using Web Services

You might also like