IP Final Review
IP Final Review
Overview
• Overview of User Input Validation
• Using Validation Controls
• Page Validation
Lesson: Overview of User Input Validation
<asp:Type_of_Validator
<asp:Type_of_Validator
id="Validator_id"
id="Validator_id"
runat="server"
runat="server"
ControlToValidate="txtName"
ControlToValidate="txtName"
ErrorMessage="Message_for_error_summary"
ErrorMessage="Message_for_error_summary"
Display="static|dynamic|none"
Display="static|dynamic|none"
Text="Text_to_display_by_input_control">
Text="Text_to_display_by_input_control">
</asp:Type_of_Validator>
</asp:Type_of_Validator>
Positioning Validation Controls on a Web Form
• Create error
messages
• Select display
mode
– Static
– Dynamic
Combining Validation Controls
• Can have multiple validation controls on a single input control
• Only the RequiredFieldValidator checks empty controls
Input Validation Controls
• RequiredFieldValidator
– InitialValue
• CompareValidator
– ValueToCompare or ControlToCompare
– Type
– Operator
• RangeValidator
– MinimumValue
– MaximumValue
– Type
Lesson: Page Validation
• Using the Page.IsValid Property
• Using the ValidationSummary Control
• Demonstration: Using the Page.IsValid
Property and the ValidationSummary
Control
Using the Page.IsValid Property
Polls all validation controls
private
private void
void cmdSubmit_Click(object
cmdSubmit_Click(object s,
s, System.EventArgs
System.EventArgs e)
e)
{{ if
if (Page.IsValid)
(Page.IsValid)
{{ Message.Text
Message.Text == "Page
"Page is
is Valid!";
Valid!";
//
// Perform
Perform database
database updates
updates or
or other
other logic
logic here
here
}}
}}
Using the ValidationSummary Control
II forget
forget who
who you
you
are!!
are!!
Types of State Management
Client-Side State
Server-Side State Management
Management
Application state Cookies
Information is available to all users Text file stores information to maintain
of a Web application state
Web
Web Server
Server
Client
Client Computer
Computer
Application and Session
variables
SessionI
D
Client-Side State Management
• Uses cookies to maintain state
– Persistent cookies
– Temporary/ Non-persistent cookies
• Less reliable than server-side state management options
– User can delete cookies
• Less secure than server-side state management options
• Limited amount of information
– Client-side restrictions on file sizes
Web
Web Server
Server
Client
Client Computer
Computer
Cookies
The Global.asax File
• Only one Global.asax file per Web application
• Stored in the virtual root of the Web
application
• Used to handle application and session events
• The Global.asax file is optional
The Global.asax File (continued)
Client
Request
Request Response
Response
ASP.NET
ASP.NET HTTP
HTTP Runtime
Runtime
Application_BeginRequest
Application_BeginRequest
Application_AuthenticateRequest
Application_AuthenticateRequest
Application_AuthorizeRequest
Application_AuthorizeRequest Application_EndRequest
Application_EndRequest
Application_ResolveRequestCache
Application_ResolveRequestCache Application_UpdateRequestCache
Application_UpdateRequestCache
Application_AquireRequestState
Application_AquireRequestState Application_ReleaseRequestState
Application_ReleaseRequestState
Application_PreRequestHandlerExecute
Application_PreRequestHandlerExecute Application_PostRequestHandlerExecute
Application_PostRequestHandlerExecute
Page
Page execution
execution
Lesson: Application and Session Variables
• Initializing Application and Session
Variables
• Using Application and Session Variables
• Demonstration: Using Session Variables
• Application and Session Variable Duration
• Scalable Storage of Application and
Session Variables
• Saving Application and Session Variables
in a Database
Initializing Application and Session Variables
• Variables are initialized in Global.asax
– The Application object shares information
among all users of a Web application
protected
protected void
void Application_Start(Object
Application_Start(Object sender,EventArgs
sender,EventArgs e)
e)
{{
Application["NumberofVisitors"]
Application["NumberofVisitors"] == 0;
0;
}}
strBgColor
strBgColor == (string)Session["BackColor"];
(string)Session["BackColor"];
lblNbVisitor.Text
lblNbVisitor.Text == Application["NumberOfVisitors"].ToString();
Application["NumberOfVisitors"].ToString();
Application and Session Variable Duration
<configuration>
<configuration>
<system.web>
<system.web>
<sessionState
<sessionState timeout="10"
timeout="10" />
/>
</system.web>
</system.web>
</configuration>
</configuration>
• Application variables persist until the
Application_End event is fired
Scalable Storage of Application and Session Variables
SQL
Client
lblAuthUser.Text
lblAuthUser.Text == User.Identity.Name;
User.Identity.Name;
lblAuthType.Text = User.Identity.AuthenticationType;
lblAuthType.Text = User.Identity.AuthenticationType;
lblIsAuth.Text
lblIsAuth.Text == User.Identity.IsAuthenticated;
User.Identity.IsAuthenticated;
Overview of Forms-Based Authentication
11 22 ASP.NET Forms
IIS Authentication
Usernam
Authenticated
66 eSomeone 44 Authorized
Access Denied
Password Logon Page
******* (Users enter
**** their credentials)
Not Submit
Submit
Authenticated 33
Authenticated
Authentication Authorized
Cookie 77 Requested
55 Secure Page
Accessing Relational Data
Using Microsoft .NET
Overview
• Overview of ADO.NET
• Creating a Connection to a Database
• Displaying a DataSet in a List-Bound Control
Lesson: Overview of ADO.NET
• What is ADO.NET?
• Using Namespaces
• The ADO.NET Object Model
• What is a DataSet?
• Accessing Data with ADO.NET
• Practice: Identifying ADO.NET Components
What is ADO.NET?
ADO.NET provides a set of classes for working with
data. ADO.NET provides:
An evolutionary, more flexible successor to ADO
A system designed for disconnected environments
A programming model with advanced XML support
A set of classes, interfaces, structures, and
enumerations that manage data access from within
the .NET Framework
Using Namespaces
• Use the Imports or using statement to
import namespaces
using
using System.Data;
System.Data;
using
using System.Data.SqlClient;
System.Data.SqlClient;
SqlDataAdapter
SqlDataAdapter
OleDbDataAdapter
OleDbDataAdapter
DataTable
SqlDataAdapter
SqlDataAdapter
Web server memory
SqlConnection
SqlConnection
Physical storage
OleDbDataAdapter
OleDbDataAdapter
OleDbConnection
OleDbConnection
SQL Server 2000 OleDb Database
Accessing Data with ADO.NET
1.11 Client makes request
Database
2.22 Create the SqlConnection and SqlDataAdapter objects
Fill the DataSet from the Web
Web SqlConnection
33 DataAdapter and close the server
server
connection
4.44 Return the DataSet to the Client SqlDataAdapte
r
55 Client manipulates the data
5.
66
6. Update the DataSet
7.
77 Use the SqlDataAdapter to
open the SqlConnection,
update the database, and DataSet
close the connection
List-Bound
List-Bound
Control
Control
Client
Client
The DataAdapter Object Model
DataSet
DataSet
DataAdapter
SelectCommand UpdateCommand InsertCommand DeleteCommand
DataReader
DataReader
Command
Command Command
Command Command
Command Command
Command
Connection
Connection
string
stringstrConn
strConn=="data
"datasource=localhost;
source=localhost;""++
"initial
"initialcatalog=northwind;
catalog=northwind;integrated
integratedsecurity=true";
security=true";
SqlConnection
SqlConnectionconnconn==new
newSqlConnection(strConn);
SqlConnection(strConn);