Friday, October 06, 2006

Introduction to ASP.NET

ASP.NET

ASP.NET is a managed framework that facilitates building server-side
applications based on HTTP, HTML, XML and SOAP. To .NET
developers, ASP.NET is a platform that provides one-stop shopping for
all application development that requires the processing of HTTP
requests.

A platform on a platform
• ASP.NET is a managed framework that facilitates building server-side
applications based on HTTP, HTML, XML and SOAP
– ASP.NET supports building HTML-based applications with Web forms,
server-side controls and data binding
– ASP.NET supports building non-visual request handlers and Web services


A new and better version of ASP
• ASP.NET is a much improved replacement for original ASP framework
– All ASP.NET code is fully compiled prior to execution
– ASP.NET doesn't require the use of scripting languages
– ASP.NET allows for total separation of code from HTML
– ASP.NET state management works in a Web farm environment


ASP.NET Internals
• ASP.NET uses a new CLR-based framework to replace ISAPI/ASP architecture
– ASP.NET requests are initially handled by the HTTP runtime of IIS
– ASP.NET ISAPI extension DLL redirects requests to ASP.NET worker process

Requests are process in the "HTTP pipeline" inside ASP.NET worker process
– Pipeline always contains HttpRuntime class
– Pipeline always contains exactly one HTTP handler object
– Modules are interceptors that can (optionally) be placed in pipeline
– HttpContext is a valuable class accessible from anywhere in pipeline


Integrated compilation support
• ASP.NET provides integrated compilation support to build source files into
DLLs in just-in-time fashion
– Auto-compilation supported for .aspx, .ascx, .asmx and .ashx files
– The generated assembly is stored in subdirectory off of CodeGen
directory
– ASP.NET automatically references all assemblies in \bin directory
– ASP.NET automatically references several commonly-used .NET
assemblies
– Other assemblies can be referenced through custom configuration
– Shadow-copying allows DLLs to be overwritten while application is
running


System.Web.UI.Page
• An .aspx file is transformed into a class that inherits from Page class
– Page class provides HTTP handler support
– Page class members are accessible from anywhere inside .aspx file
– Much of Page class dedicated to generation of HTML
– Static HTML in .aspx file becomes part of page's Render method
– Code render blocks in .aspx file become part of page's Render method
– Members defined in code declaration blocks become members of page
class
– WebForms and server-side controls build on top of Page class
architecture


ASP.NET directives
• ASP.NET supports several important page-level directives
– @Page directive controls how the page file is compiled
– @Page directive can take many different attributes
– @Assembly directive replaces the /r command-line switch to
VBC.EXE
– @Import directive replaces the VB.NET Imports statement


Using a code-behind source file
• ASP.NET provides various code-behind techniques promote a separation of
code and HTML
– Types inside a code-behind file are accessible from a .aspx file
– Pre-compiled code-behind files are placed in the \bin directory
– Code-behind source files can compiled on demand using the Src
attribute
– Code-behind source files have extensions such as .vb or .cs
– Compiling code-behind files on demand is useful during development
– Compiling code-behind files on demand shouldn't be used in production


web.config
• ASP.NET configuration is controled by a XML-based file named
web.config
– web.config must be placed in IIS application's root directory
– compilation section controls compiler stuff
– httpRuntime section controls request execution
– pages section controls how pages are compiled and run
– Many other ASP.NET-specific section are available


Creating a custom HTTP handler
• IHttpHandler defines the semantics for an object that will serve as
the end point for an HTTP request in the ASP.NET framework
– IHttpHandler is defined by ASP.NET in the System.Web
namespace
– AnyIHttpHandler-compatible object can used as an ASP.NET
handler
– It's simple to write and configure a handler as a plug-compatible
component
– web.config file can be configured to dynamically load
assembly/class
– Use of .ashx files eliminates need to configure web.config file


Debugging ASP.NET applications
• ASP.NET provides extensive debugging support
– compilation section in web.config must enabled debugging
– You can use either Visual Studio .NET or DbgClr.exe
– Choose Debug Processes from the Tools menu
– Attach debugger to ASP.NET worker process ASPNET_WP.EXE
– Open source files inside debugger and set breakpoints
– Execute page by submitting request as usual with browser


Creating HTML-based applications
• ASP.NET is more than just ASP 4.0
– Unlike ASP, ASP.NET is HTML-aware
– Lots of internal Page class code dedicated to forms/control processing
– Code-behind techniques encourage better separation of code from HTML
– Extensible, server-side control architecture
– Server-side data binding model
– Form validation architecture


Using code-behind inheritance
• An ASP.NET page can inherit from another custom Page-derived class
– Code-behind inheritance allows you to remove all code from .aspx
files
– Your code goes into a custom class that inherits from the Page
class
– Custom page class goes into a separate source file
– The .aspx file uses Inherits attribute inside @Page directive
– Separation of code and HTML (i.e. presentation) significantly
improve the maintainability of an HTML-based application


User versus Programmatic Interfaces
• ASP.NET applications may expose both user and programmatic
interfaces
– User interface expressed through HTML
– Handled by System.Web.UI.*
– Programmatic interfaces exposed via XML/SOAP
– Programmatic interface handled by System.Web.Services.*


Web Methods
• Web services are .NET methods marked with the WebMethod attribute
– Authored like any other method you might write, with a file
extension of .asmx
– ASP.NET takes care of mapping incoming HTTP requests onto
calls on your object
– .NET provides proxy classes on the client side that make calling
web services as trivial as calling other functions
– Client-side proxy takes care of generating HTTP request to server,
and parsing response as return value.

Best Regards,
Duane Aritonang
Chief Technology Officer
http://www.ArtDuane.com