Advanced ASP 'Net 2'0 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Advanced ASP 'Net 2'0

Description:

Writing custom HTTP handlers. Creating Asynchronous ASP.Net Pages. ASP.Net ... ASP.NET 2.0 APPLICATIONS Advanced Topics by Dino Esposito, Microsoft Press. ... – PowerPoint PPT presentation

Number of Views:231
Avg rating:3.0/5.0
Slides: 26
Provided by: gerald115
Category:

less

Transcript and Presenter's Notes

Title: Advanced ASP 'Net 2'0


1
Advanced ASP .Net 2.0
  • Gerald Walsh
  • GT Data Systems
  • MCSD, MCAD, MCT, MVP

2
Agenda
  • Writing custom HTTP handlers
  • Creating Asynchronous ASP.Net Pages

3
ASP.Net Request Processing
ASPNET_WP.EXE
Request is passed to the ASP.Net ISAPI
Interface ASPNET_ISAPI.dll via Named Pipe
HTTP Pipeline
HTTP Request
Web.config
HTTP Response
IIS 6.0 Server ISAPI Processes Request INETINFO.EX
E or DLLHOST.EXE
HTML Response Is returned back through the
ASP.Net pipeline.
ASP.Net HTTP Handler Code
4
the HTTP pipeline
  • Foundation for ASP.NET pages Web Services
  • General-purpose framework for server-side HTTP
    programming

Pipeline Classes
Context Classes
5
Writing Custom HTTP Handlers
  • ASP.Net is based on processing custom handlers.
  • It provides several well known built-in handlers
  • Page
  • Web Service
  • .Net Remoting
  • Building Custom Handlers allow you to develop
    your own processes in addition to these.
  • Custom handlers can offer much greater
    performance than using pages and can process
    requests in custom non-standard ways.
  • Implemented as a separate assembly or as an ASHX
    file.

6
The IHttpHandler Interface
  • Imports System
  • Imports System.Web
  • Public Class Handler Implements IHttpHandler
  • Public Sub ProcessRequest(ByVal context As
    HttpContext) Implements _ IHttpHandler.ProcessRequ
    est
  • Code here to process request using
    context object
  • End Sub
  • Public ReadOnly Property IsReusable() As
    Boolean Implements _ IHttpHandler.IsReusable
  • Get
  • Return True
  • End Get
  • End Property
  • End Class

7
Registering Your Handler
  • Edit Web.config
  • ltconfigurationgt
  • ltsystem.webgt
  • lthttpHandlersgt
  • ltadd verb path.hdlr
  • typeMyNamespace.MyHandlerClass, assembly
  • validatefalse/gt
  • lt/httpHandlersgt
  • lt/system.webgt
  • lt/configurationgt

8
Registering Your Handler in IIS6
  • Register your custom file extension in the IIS
    Metabase.
  • Web Application Properties ?
  • Configuration ?
  • Mappings
  • Executable Path set to aspnet_isapi.dll

9
Registering Handlers in IIS7
10
Registering Handlers in IIS7
11
Alternate Method
  • Add a ASHX resource to your project
  • Includes a special directive
  • lt_at_ WebHandler LanguageVB ClassNamespace.MyHa
    ndler gt
  • The handler will run automatically when invoked,
    no registration or deployment is necessary.
  • The registration is actually handled by another
    built-in handler.
  • Quick Tip Add a CodeBehind attribute to the
    WebHandler directive to use intellisense and
    other code editor capabilities.

12
DEMO
  • Building a simple HTTP Handler

13
Asynchronous Pages
  • By default ASP.Net pages execute synchronously.
  • When IIS is serving a large number of requests it
    can run out of available threads.
  • IIS then returns a 503 Server Too Busy
    response.
  • Async requests improve web server performance by
    reducing thread contention in the ASP.Net process
    request thread pool.
  • By default ASP.Net request queue holds a maximum
    of 100 threads.
  • appRequestQueueLimit can be set up to 5000

14
The Page Async Attribute
  • lt_at_ Page Asynctrue . . . gt
  • Causes the page parser to generate the
    IHttpAsyncHandler interface in the dynamically
    generated class.
  • This then allows for asynchronous handlers to be
    registered for the PreRenderComplete event.

15
IHttpAsyncHandler
  • A standard Async processing design pattern that
    Implements two methods
  • BeginProcessRequest(HttpContext, callback,
    object)
  • EndProcessRequest(IAsyncResult)

16
AddOnPreRenderCompleteAsync
  • Handles registration of asynchronous event
    handlers to execute during the pages
    PreRenderComplete event.
  • AddOnPreRenderCompleteAsync(
  • new BeginEventHandler(BeginProc),
  • new EndEventHandler(EndProc)
  • )

17
Uses for Async Pages
  • Long Running or Slow Database Operations.
  • Calling Web Services.
  • Fire and Forget Web Page Requests.

18
DEMO
  • Building an Asynchronous ASPX Page

19
Resources
  • Gerald_at_GTDataSystems.com
  • Book Programming Microsoft ASP.NET 2.0
    APPLICATIONS Advanced Topics by Dino Esposito,
    Microsoft Press.
  • http//www.ASP.Net
  • http//msdn.microsoft.com
  • http//msdn.microsoft.com/msdnmag/issues/02/09/htt
    ppipelines/

20
The ASP.net Cache Object
  • A hashtable used to store frequently accessed
    data.
  • Global to the application.
  • Similar to the Application object but has
    additional management functionality.
  • Dependency Functionality
  • Sliding and Fixed Expiration of Data
  • Prioritization of data in cache

21
Cache.Add
  • Cache.Add(
  • Key as string,
  • Value as object,
  • Dependencies as CacheDependency,
  • AbsoluteExpiration as Date,
  • SlidingExpiration as timespan,
  • Priority as CacheItemPriority,
  • onRemovedCallback as CacheItemRemovedCallback
  • )

22
Cache Dependencies
  • CacheDependency Object
  • Can Be
  • File
  • Directory
  • SQL Server Data Dependency
  • Custom Dependency
  • Can be bound to multiple cache items
  • Cache.Insert(Key, Value, Dependency)

23
SQL Cache Dependency
  • Supported on SQL 7.0 and later
  • Managed with the SqlCacheDependencyAdmin object
  • SQL Must first be configured to support
    dependencies.
  • Use aspnet_regsql.exe d ltdbnamegt or
    EnableNotifications method in code.

24
SQL Cache Dependency
  • Creates a table in the DB to track data changes
    in enabled tables. AspNet_SqlCacheTablesForChangeN
    otification
  • Call to EnableTableForNotifications adds triggers
    and table entry to track changes.
  • SqlCacheDependency object periodically queries
    the table to check for data changes.

25
DEMO
  • Using the Cache Object
Write a Comment
User Comments (0)
About PowerShow.com