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:

  enableCaching="true" />

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.

Other configuration sections in web.config include the ASP.NET AJAX profile service, which is used to access personalization information, and the authentication service, which is used to log users in and out of an application. You can also use the JSON [JavaScript Object Notation] serialization configuration to limit JSON message sizes that will be processed, restricting the number of object levels that can be processed and integrating custom JSON serialization classes.

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:

<asp:ScriptManager id="sm" 
  runat="server" />

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.

About the Author

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.

comments powered by Disqus


  • GitHub Copilot for Azure Gets Preview Glitches

    This reporter, recently accepted to preview GitHub Copilot for Azure, has thus far found the tool to be, well, glitchy.

  • New .NET 9 Templates for Blazor Hybrid, .NET MAUI

    Microsoft's fifth preview of .NET 9 nods at AI development while also introducing new templates for some of the more popular project types, including Blazor Hybrid and .NET MAUI.

  • What's Next for ASP.NET Core and Blazor

    Since its inception as an intriguing experiment in leveraging WebAssembly to enable dynamic web development with C#, Blazor has evolved into a mature, fully featured framework. Integral to the ASP.NET Core ecosystem, Blazor offers developers a unique combination of server-side rendering and rich client-side interactivity.

  • Nearest Centroid Classification for Numeric Data Using C#

    Here's a complete end-to-end demo of what Dr. James McCaffrey of Microsoft Research says is arguably the simplest possible classification technique.

  • .NET MAUI in VS Code Goes GA

    Visual Studio Code's .NET MAUI workload, which evolves the former Xamarin.Forms mobile-centric framework by adding support for creating desktop applications, has reached general availability.

Subscribe on YouTube