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:

<scriptResourceHandler   
  enableCompression="true" 
  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

Featured

  • Full Stack Hands-On Development with .NET

    In the fast-paced realm of modern software development, proficiency across a full stack of technologies is not just beneficial, it's essential. Microsoft has an entire stack of open source development components in its .NET platform (formerly known as .NET Core) that can be used to build an end-to-end set of applications.

  • .NET-Centric Uno Platform Debuts 'Single Project' for 9 Targets

    "We've reduced the complexity of project files and eliminated the need for explicit NuGet package references, separate project libraries, or 'shared' projects."

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

Subscribe on YouTube