Notes
Slide Show
Outline
1
 
2
Localize Web Apps Quickly
and Easily
  • Browsers transmit Accept-Language headers identifying language preferences
  • You can use this information to localize output from FCL methods called by ASP.NET apps
    • Application_BeginRequest
    • Thread.CurrentCulture
    • CultureInfo

3
Global.asax
4
Use Custom HTTP Handlers to Extend ASP.NET
  • HTTP handlers are classes that handle HTTP requests
    • Mapped to file names and file name extensions in CONFIG files
    • Implement IHttpHandler
  • Built-in handlers handle requests for ASPX files, ASMX files, and other ASP.NET file types
  • Custom HTTP handlers respond to requests in any way you want
    • Generate images from user input (e.g., graphs)
    • Convert XML to HTML using XSLT
5
Hello.ashx
6
Invoking Hello.ashx
7
ASHX Image Generator Template
8
Image Generator Template, Cont.
9
Use the Application Cache to
Write Apps that Scream
  • Common performance bottlenecks in Web apps:
    • File accesses
    • Database accesses
  • ASP.NET application cache provides a fast and easy-to-use means for caching data (any data) to minimize I/O
    • Can hold anything derived from System.Object
    • Supports expiration policies and dependencies
    • Optionally notifies you when an item is removed
  • A key to great performance!
10
Using the Application Cache
11
Temporal Expiration (Absolute)
12
Temporal Expiration (Sliding)
13
File Dependency Expiration
14
Cache Removal Callbacks
15
Cache Removal Callbacks, Cont.
16
Use the Page Output Cache
to Intensify the Screaming
  • Fetching an ASPX Web page incurs overhead
  • ASP.NET page output cache reduces overhead by caching output from pages
    • You control cache duration
    • You control other caching parameters, too
  • Caching can be performed at two levels:
    • Page level (ASPX files)
    • Sub-page level (ASCX files)
17
Page Caching
18
The VaryByParam Attribute
  • To cache different versions of a page based on the value of an input parameter, identify the parameter with VaryByParam



  • Separate multiple parameters with semicolons



  • Use * to represent any input parameter
19
Sub-Page (Fragment) Caching
20
The VaryByControl Attribute
  • To cache different versions of a user control based on the value of a property, identify the property with VaryByControl



  • Separate multiple properties with semicolons



  • Use * to represent any property
21
Use Application_Error to Trap Unhandled Exceptions
  • Fired when unhandled exceptions occur
  • Process them in Global.asax and let someone know that the application is sick
  • Should be considered de rigueur in ASP.NET apps!
22
Example 1
  • Record error in system event log
23
Example 2
  • E-mail a system administrator
24
Use ItemCreated Events to Customize DataGrids
  • DataGrid controls are highly customizable
    • Public properties
    • Custom columns (including TemplateColumns)
    • ItemCreated events
  • ItemCreated events are the key to advanced DataGrid customizations
    • Fired for each row rendered by a DataGrid
    • Use them to customize a DataGrid’s HTML output
    • Use them to inject client-side script


25
Rainbow DataGrid
26
Rainbow DataGrid, Cont.
27
Rainbow DataGrid - The Output
28
Eliminate Unnecessary View State
  • Many ASP.NET server controls use view state to persist state from one request to the next
    • TextBox, ListBox, and so on
    • View state is round-tripped in __VIEWSTATE controls
  • View state often isn’t necessary
    • Used to fire change events
    • Used to preserve state in controls whose state isn't fully encapsulated in postback data
  • Disable view state when it isn’t needed
    • Reduces the data passed in each request
    • Increases performance
29
This is Wasteful
30
This is Not
31
The Difference
  • Without EnableViewState=“false”





  • With EnableViewState=“false”
32
Use EnableViewStateMac to Prevent View State Tampering
  • By default, ASP.NET doesn’t verify that view state round-tripped to the client and back isn’t altered
    • Leaves open the possibility of tampering
  • Use EnableViewStateMac to prevent tampering
    • For an individual page



    • For all pages
33
Use Derivation to Modify ASP.NET Web Controls
  • Derive from Control or WebControl to create “from-scratch” custom controls
  • Derive from existing control classes to leverage functionality already built in
    • Override inherited methods and properties as needed (especially the Render method)
    • Add new methods and properties, too
34
NumTextBox Control
35
NumTextBox Control, Cont.
36
Use WinForms Controls to Build Rich Browser UIs
  • HTML is a limited medium for expressing UIs
  • Browser-based UIs can be made richer with client-side script, but even that only goes so far
  • Use Windows Forms controls in Web pages to build ultra-rich browser-based UIs
    • Requires .NET Framework on the client
    • Requires IE 5.01 or higher
  • For a cool sample, see http://www.wintellect.com/resources/faqs/-default.asp?faq_id=1&page=5
37
WebSlider Control
38
Using the WebSlider Control