Wahlin on .NET
Configure ASP.NET AJAX Extensions
Explore ASP.NET AJAX configuration sections in web.config, and learn how handlers and modules fit into the overall picture.
In my previous column, I discussed the technologies on which AJAX relies, how you can create custom AJAX scripts to perform asynchronous postbacks, and productivity gains that the ASP.NET AJAX Extensions provide in general. In this column, I'll focus on ASP.NET AJAX configuration entries in web.config as well as on the role new HttpHandler and HttpModule classes play in AJAX-enabling Web sites.
Create a New ASP.NET AJAX Web Site
Once you've installed the ASP.NET AJAX Extensions from http://ajax.asp.net, you will see a new template named "ASP.NET AJAX-Enabled Web Site" in Visual Studio .NET 2005's New Web Site dialog (see Figure 1).
When you use the ASP.NET AJAX-Enabled Web Site template to create a new Web site, you add a specialized web.config file that contains various configuration entries for enabling ASP.NET AJAX functionality on the server side. The ASP.NET AJAX Extensions documentation breaks down each of the configuration tags added into web.config here.
The top portion of the web.config file contains several different section configuration tags. These tags define classes that perform the task of parsing configuration data defined in web.config at run time. For example, the scriptResourceHandler section tag specifies that the System.Web.Configuration.ScriptingScriptResourceHandlerSection class should be used to parse data defined in the scriptResourceHandler tag shown here:
This tag provides configuration information used by the run-time engine to determine if script resources embedded in assemblies are compressed and/or cached. Both compression and caching are enabled by default, although the compression setting will not have an effect in browsers that don't support compression.
The authentication, profile and JSON serialization configuration tags are commented out by default, but you can easily enable them by removing the appropriate comment tags. (In a future column, I'll discuss the profile and authentication services and show you how they can be used in AJAX applications.)
Prefixes, Handlers and Modules
In addition to defining custom configuration sections used by the ASP.NET AJAX Framework, web.config maps the standard "asp" server control prefix to the System.Web.Extensions assembly (see Listing 1).
This allows you to use AJAX server-side controls, such as the ScriptManager and UpdatePanel, as you would any other standard ASP.NET server control. Prefix the desired control with "asp" and it's ready to use:
Web.config also defines two HttpHandlers and one HttpModule. All three play key roles. Review the definitions for these sections in Listing 2.
The two HttpHandlers that are defined include ScriptHandlerFactory and ScriptResourceHandler. ScriptHandlerFactory performs a variety of tasks such as handling calls made to back-end services (Web Services, profiles and authentication services). ScriptResourceHandler handles requests made to scripts embedded in the ASP.NET AJAX Extensions assemblies.
An HttpModule called ScriptModule is also defined. It handles authentication as well as routing calls to Web services using REST [Representational State Transfer]. REST is internally used for ASP.NET AJAX Web service calls. You can find more information about REST here.
Using the new ASP.NET AJAX-Enabled Web Site template simplifies the process of configuring a Web site to use ASP.NET AJAX data, controls and HttpHandlers and HttpModules. In this column, you've learned about some of the configuration sections in web.config, and learned how handlers and modules fit into the overall picture. In the next column, I'll introduce a few of the ASP.NET AJAX server controls that you can use to AJAX-enable a Web site.
Dan Wahlin (Microsoft MVP for ASP.NET and XML Web Services) is the founder of The Wahlin Group which specializes in .NET and SharePoint onsite, online and video training and consulting solutions. Dan also founded the XML for ASP.NET Developers Web site, which focuses on using ASP.NET, XML, AJAX, Silverlight and Web Services in Microsoft's .NET platform. He's also on the INETA Speaker's Bureau and speaks at conferences and user groups around the world. Dan has written several books on .NET including "Professional Silverlight 2 for ASP.NET Developers," "Professional ASP.NET 3.5 AJAX, ASP.NET 2.0 MVP Hacks and Tips," and "XML for ASP.NET Developers." Read Dan's blog here.