Professional Documents
Culture Documents
Advanced Web Forms
Advanced Web Forms
Mark Sapossnek
CS 594
Computer Science Department
Metropolitan College
Boston University
Prerequisites
This module assumes that you understand the
fundamentals of
C# programming
ADO.NET
Introduction to ASP.NET and Web Forms
Learning Objectives
Assorted topics in ASP.NET
Developing web applications with ASP.NET
Agenda
IIS Deployment
Web Applications Availability
Configuration Security
Tracing HTTP Runtime
State Management Targeting Uplevel Clients
Caching Creating Controls
Error Handling Developing Web Forms
IIS
Internet Information Server
Microsoft’s web server
Foundation for ASP.NET
Runs in inetinfo.exe process
Also FTP, NNTP, SMTP
Shared resources
Default location c:\inetpub\wwwroot
Internet Services Manager
A Microsoft Management Console (MMC) snap-in
IIS
Virtual Directories
void Application_OnStart() {
Application["startTime"]=DateTime.Now.ToString();
}
void Session_OnStart() {
Session["startTime"]=DateTime.Now.ToString();
}
Web Applications
global.asax
Can use code-behind
Can contain application-level directives
<%@ Application Description=“This is my app…” %>
<%@ Application Inherits=“MyBaseClass” %>
<%@ Application Src=“Global.cs” %>
Visual Studio.NET uses this
<%@ Import Namespace=“System.Collections” %>
<%@ Assembly Name=“MyAssembly.dll” %>
Agenda
IIS Deployment
Web Applications Availability
Configuration Security
Tracing HTTP Runtime
State Management Targeting Uplevel Clients
Caching Creating Controls
Error Handling Developing Web Forms
Configuration
Goal
Provide extensible configuration for admins &
developers to hierarchically apply settings for an
application
Solution
Store configuration data in XML text files
Format is readable and writable by people and machines
Configuration
Settings specified in configuration sections, e.g.
Security, SessionState, Compilation,
CustomErrors, ProcessModel, HTTPHandlers,
Globalization, AppSettings, WebServices,
WebControls, etc.
Configuration information stored in web.config
It is just a file, no DLL registration, no Registry
settings, no Metabase settings
<!-- web.config can have comments -->
Configuration
Configuration Hierarchy
Root web.config
Dir
Sub
Dir1
Sub
Dir2
Configuration
web.config Sample
<configuration>
<configsections>
<add names=“httpmodules“
type=“System.Web.Config.HttpModulesConfigHandler“/>
<add names=“sessionState“
type=“...“/>
</configsections>
<httpModules>
<!--- http module subelements go here -->
</httpModules>
<sessionState>
<!--- sessionstate subelements go here -->
</sessionState>
</configuration>
Configuration
Configuration Hierarchy
C:\WINNT\Microsoft.NET\Framework\v1.0.2914\config\machine.config
Configuration
User-defined Settings
Methods
Trace.Write: Writes category and text to trace
Trace.Warn: Writes category and text to trace in red
Properties
Trace.IsEnabled: True if tracing is turned on for
the application or just that page
Trace.Mode: SortByTime, SortByCategory
Implemented in System.Web.TraceContext class
Tracing
Page-Level Tracing
Demo: Trace1.aspx
Show information obtained from tracing
Tracing
Tracing Into A Component
Client
Store the data on one or more
of the physical tiers
Web Servers
Data can be
per-user permanent,
per-user (session) or Database
per-application
State Management
Client
Application variables
Shared by all sessions (users)
Session variables
Still need to pass session id through the client
ASP.NET State Service or database
Caching
Similar to application variables, but can be updated
periodically or based upon dependencies
State Management
Database
Application-level
Part of application database design
Session-level
Custom session state management in database
ASP.NET database session state support
State Management
In ASP.NET
<sessionstate inproc="false"
server=“AnotherServer" port="42424"
usesqlserver=“true” />
State Management
Session Variables
Demo: ApplicationAndSession.aspx
State Management
Transfering Control Between Pages
Link to a page
Postback
Response.Redirect
Causes HTTP redirect
Tells browser to go to another URL
Server.Transfer
Like a redirect but entirely on one server
Server.Execute
Execute one page from another then return control
Both pages processed on same server
Agenda
IIS Deployment
Web Applications Availability
Configuration Security
Tracing HTTP Runtime
State Management Targeting Uplevel Clients
Caching Creating Controls
Error Handling Developing Web Forms
Caching
Many sites spend considerable effort generating
the same web pages over and over
For example, a product catalog changes overnight,
but is accessed tens of thousands of times a day
Server-side caching can vastly improve
performance and scalability
ASP.NET provides support for
Page output caching
Data caching
Caching
Page Output Caching
defaultredirect=“error.htm”>
<error statuscode=“404”
redirect=“adminmessage.htm”/>
<error statuscode=“403”
redirect=“noaccessallowed.htm”/>
</customerrors>
</configuration>
Error Handling
Error Events
Deadlocks
<processmodel requestqueuelimit=“500” />
Availability
Preemptive Recycling
Application
HTTP Module Http Context
HTTP Module
HTTP Module
Managed
ASP+ HTTP Runtime code
Native
Host (IIS 5, IIS 4, IE) code
HTTP Runtime
HTTPContext
HttpContext is an object that encapsulates all
information about an individual Http Request
within ASP+
System.Web.HttpContext
HttpHandler and HttpModules access to
ASP.NET intrinsics via HttpContext
“Flowed” throughout request lifetime
HttpHandlers and HttpModules can also
“add” objects into HttpContext
Objects then flowed throughout request
HTTP Runtime
System.Web.HTTPContext
public class HttpContext {
public HttpRequest Request { get; }
public HttpResponse Response { get; }
public HttpServerUtility Server { get; }
public HttpApplication Application { get; }
public HttpSession Session { get; }
public IPrincipal User { get; }
public Cache Cache { get; }
public IDictionary Items { get; }
ProcessRequest() Method
Method that processes individual request
IsReusable() Method
Indicates whether pooling is supported
HTTP Runtime
HttpHandler Registration
1. Compile and deploy .NET Library DLL within “bin” dir
under application vroot
2. Register HttpHandler in web.config
<configuration>
<httphandlers>
<add verb=“*” path=“foo.bar” type=“assembly#class”/>
</httphandlers>
</configuration>
if (Request.Browser.Frames == True) {
// Use frames
}
Agenda
IIS Deployment
Web Applications Availability
Configuration Security
Tracing HTTP Runtime
State Management Targeting Uplevel Clients
Caching Creating Controls
Error Handling Developing Web Forms
Creating Controls
ASP.NET provides two ways to create your own
server-side controls
User Controls: Essentially a mini .aspx file
Formerly called a “Pagelet”
Custom Controls: You derive a class from
System.Web.UI.Control
Creating Controls
User Controls
Provide a simple way for page developers to
author controls
Stored in a .ascx file
Not just a server-side include
Enables full encapsulation
Supports nested controls
Separate code namespace
Separate code language
Can partition work across multiple developers
Great way to reuse work across multiple pages and
applications
Creating Controls
Registering User Controls
...
<Acme:Message runat="server"/>
Creating Controls
Exposing a User Control Object Model
<font color=<%=Color%>>
This is a simple message pagelet
</font>
Creating Controls
Programmatic Use of User Controls
Page.LoadControl(string source)
Dynamically instantiates a user control
Get and customize an instance:
foo = Page.LoadControl("foo.ascx");
foo.color = "red“;
using System;
using System.Web;
using System.Web.UI;
http://www.ibuyspy.com
Developing Web Forms
Debugging
IIS Deployment
Web Applications Availability
Configuration Security
Tracing HTTP Runtime
State Management Targeting Uplevel Clients
Caching Creating Controls
Error Handling Developing Web Forms
Resources
Quick Start Tutorial
http://localhost/quickstart/ASPPlus/default.htm
ASP.NET Overview
http://msdn.microsoft.com/msdnmag/issues/0900/ASPPlus/AS
PPlus.asp
Caching
http://msdn.microsoft.com/voices/asp04262001.asp
Session state
http://msdn.microsoft.com/library/default.asp?URL=/libra
ry/welcome/dsmsdn/asp12282000.htm
Validation
http://msdn.microsoft.com/library/techart/aspplusvalid.h
tm
Tracing
http://msdn.microsoft.com/library/default.asp?URL=/
library/welcome/dsmsdn/asp01252001.htm
Thank you