Thursday, April 22, 2010

Configure AJAX In Sharepoint 2007

For enabling Ajax in SharePoint 2007, We need first to configure SharePoint Portal to support AJAX. We can do it in following way -
  • Installing ASP.NET AJAX on servers in your farm
    • install the full " AJAX Extensions " from
      ajax.asp.net
    • Download ajextoolkit -
      http://ajaxcontroltoolkit.codeplex.com/releases/view/11121
  • Configure SharePoint to support AJAX & AjaxControlToolkit
    For enabling Ajax in SharePoint 2007, you need first to configure SharePoint to support AJAX. For this we need to add some configuration settings in web.config file.Locate your default web.config file ("C:\Inetpub\wwwroot\wss\VirtualDirectories\YourWebAppPortNo\web.config").

    • Add the following part under: <configSections>
      <configuration>
      <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
      </sectionGroup>
      </sectionGroup>
      </sectionGroup>
      </configSections>
    • add the AJAX controls dll to SharePoint Safe Controls, so copy the following part under: <SafeControls>
      <SafeControls>
      <SafeControl Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TypeName="*" Safe="True" />
      <!-- Usually not required ,in case of any issues you can try to uncomment this. -->
      <!--<SafeControl Assembly="AjaxControlToolkit, Version=1.0.20229.20821, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" Namespace="AjaxControlToolkit" TypeName="*" Safe="True" />-->

      </SafeControls>
    • Add the following part under: <httpHandlers>
      <httpHandlers>
      <remove verb="GET,HEAD,POST" path="*" />
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
      </httpHandlers>
    • Add the following part under: <httpModules>
      <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </httpModules>
    • Add the following part under : <compilation><assemblies> - the version number can change according to your .net installation
      <compilation batch="false" debug="true">
      <assemblies>
      <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <!-- for enabling ajax tool kit support -->
      <add assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28F01B0E84B6D53E"/>
      </assemblies>
      </compilation>
    • Add the following part under: <pages >
      <pages enableSessionState="false" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">
      <controls>
      <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <!-- Add this to support the Control Kit -->
      <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="cc1"/>
      </controls>
      </pages>
    • At the end of web.config add the following part under:
      <configuration>
      <!--
      <system.web.extensions>
      <scripting>
      <webServices>
      -->
      <!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
      <!--
      <jsonSerialization maxJsonLength="500">
      <converters>
      <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
      </converters>
      </jsonSerialization>
      -->
      <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
      <!--
      <authenticationService enabled="true" requireSSL = "true|false"/>
      -->
      <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and writeAccessProperties attributes. -->
      <!--
      <profileService enabled="true"
      readAccessProperties="propertyname1,propertyname2"
      writeAccessProperties="propertyname1,propertyname2" />
      -->
      </webServices>
      <!--
      <scriptResourceHandler enableCompression="true" enableCaching="true" />
      -->
      </scripting>
      </system.web.extensions>
      -->
      <!--<system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </modules>
      <handlers>
      <remove name="WebServiceHandlerFactory-Integrated" />
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
      type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
      type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </handlers>
      </system.webServer>
      -->
      </configuration>
    • Save your web.config file, restart IIS
  • Include the AJAX script Manager to the master page, e.g.include the script manager control in the default.master(C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL)
    According to your portal template; locate the right master page file or you can open the master page from the SharePoint Designer under _catalogs folder.After you locate the master page file open the file then put the following line inside the top of <form> tag
    As shown below:
    <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
    <WebPartPages:SPWebPartManager id="m" runat="Server" />
    <asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
  • Also you should copy the DLL “AjaxControlToolkit.dll” into your SharePoint Bin Folder:
    C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin
    Also add it on GAC of you are planning to access it from a Shared assembly

Troublshooting -

  • Download the correct version of System.Web.Extensions & ajextoolkit according to .net framework installation.And Change the Version numbers in web.config
  • You can also Get the Sharepoint 2007 AJAX toolkit from CodePlex http://www.codeplex.com/sharepointajax
  • Always keep a backup of the web.config file (important, if something goes wrong you might need to revert to the old one)
  • Make sure SharePoint has access to AjaxControlToolkit.dll. Copy the dll assembly to the BIN/Global Assembly Cache (GAC)
  • In case of accessibility issue for tool kit , copy all AJAXTOOLKIT files and directories to C:\Inetpub\wwwroot\wss\VirtualDirectories\Port\_app_bin folder
  • In case of security issues try to , Add AjaxToolKit.dll to SafeControls in web.config
  • In case of any issues with ScriptManager in your master page - Instead of asp:scriptManager ... add the ToolkitScriptManager to your master page
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

No comments: