Enable AJAX Recipe

The guidance package includes the recipe named Enable Ajax, which allows you to enable a Web site to use ASP.NET AJAX Extensions. After you register (or install) the guidance package, the recipe is available on the Solution Explorer shortcut menu that appears when you right-click the Web site root node. Figure 1 illustrates the recipe menu.
Figure 1
The Enable Ajax recipe menu.

Implementation Details

You can find the recipe definition in the EnableWebClientFactoryAjax.xml file (this file is located in the Recipes folder of the WebClientFactoryPackage project).
You use the HostData section in a recipe definition to specify where in the Visual Studio interface the recipe will be shown. In the EnableWebClientFactoryAjax.xml file, two command bars are defined in the HostData section.

  <CommandBar Menu="WCSFWebProject" />
  <CommandBar Menu="WCSFWebApplicationProject" />

The first command bar is associated with the WCSFWebProject menu; the second command bar is associated with the WCSFWebApplicationProject menu.
The WCSFWebProject menu is displayed when the user right-clicks a Web site node in Solution Explorer; the WCSFWebApplicationProject menu is displayed when the user right-clicks a Web Application project node in Solution Explorer.
The WCSFWebProject menu and the WCSFWebApplicationProject menu are defined in the file WebClientFactoryPackage.xml located in the root of the WebClientFactoryPackage project.

<Menu Name="WCSFWebProject" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Web Project"/>
<Menu Name="WCSFWebApplicationProject" Text="Web Client Factory" Priority="1">
  <CommandBar Guid="D309F791-903F-11D0-9EFC-00A0C911004F" ID="1026"/>

The Enable Ajax recipe updates the Web.config file to include the elements required to support Microsoft ASP.NET AJAX. To do this, the actions in the following XML are executed.

<Action Name="GetOrCreateWebconfig" Type="Microsoft.Practices.WebClientFactory.Actions.GetOrCreateProjectItemAction, Microsoft.Practices.WebClientFactory.GuidancePackage">
  <Input Name="Project" RecipeArgument="SelectedWebProject"/>
  <Input Name="ItemName" RecipeArgument="WebConfigFileName"/>
  <Input Name="Template" RecipeArgument="WebConfigPath"/>
  <Output Name="ProjectItem"/>
<Action Name="LoadXml" Type="Microsoft.Practices.RecipeFramework.Library.XML.Actions.LoadXmlAction, Microsoft.Practices.RecipeFramework.Library">
  <Input Name="ProjectItem" ActionOutput="GetOrCreateWebconfig.ProjectItem"/>
  <Output Name="XmlDoc"/>
<Action Name="EnableAjaxOnWebProject" Type="Microsoft.Practices.WebClientFactory.Actions.EnableAjaxOnWebProjectAction, Microsoft.Practices.WebClientFactory.GuidancePackage">
  <Input Name="Project" RecipeArgument="SelectedWebProject"/>
  <Input Name="XmlDoc" ActionOutput="LoadXml.XmlDoc"/>
<Action Name="SaveXml" Type="Microsoft.Practices.RecipeFramework.Library.XML.Actions.SaveXmlAction, Microsoft.Practices.RecipeFramework.Library">
  <Input Name="ProjectItem" ActionOutput="GetOrCreateWebconfig.ProjectItem"/>
  <Input Name="XmlDoc" ActionOutput="LoadXml.XmlDoc"/>

The Enable Ajax recipe performs the steps described in the topic Configuring ASP.NET AJAX. For a detailed description of the steps performed by the recipe, see the section “Adding ASP.NET AJAX Configuration Elements to an Existing Web Site” in the aforementioned topic.

After modifying the content of the Web.config file, the following action adds a reference in the selected project to the System.Web.Extensions.dll assembly.

<!-- Add references to System.Web.Extensions -->
<Action Name="AddExtensionsAssemblyReferenceToWeb" Type="AddAssembliesReferenceAction">
  <Input Name="FileNames" RecipeArgument="WebExtensionsAssembly"/>
  <Input Name="ReferringProject" RecipeArgument="SelectedWebProject"/>
  <Input Name="AssembliesPath" RecipeArgument="WebExtensionsAssemblyPath"/>

Enable AJAX Next Steps


Last edited Nov 12, 2007 at 4:08 PM by siacomuzzi, version 2


No comments yet.