MOSS 2007: Add support for AJAX in your SharePoint installation 

Author: Tobias Zimmergren
Url:
http://www.zimmergren.net

In this very short and straight-on post I'll just mention how you can configure your SharePoint installation to enable support for ASP.NET AJAX 1.0 since a lot of people have been asking me about it.

Before we make any changes in the web.config we need the following:

  • A backup of the web.config file (important, because if something goes wrong you might need to revert to the old one)
  • SharePoint (WSS 3.0 or MOSS 2007)
  • ASP.NET 2.0 AJAX 1.0 Extensions
  • Be in the mood for some copy/pasting the following 5 minutes

Copy/Paste time

Locate your default web.config file (usually here: "C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config").
Edit the web.config file according to this scenario:

  1. Locate the <configSections> element and add the following code inside it:

      <sectionGroup name="system.web.extensions"
      type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35">

      <sectionGroup name="scripting"
      type="System.Web.Configuration.ScriptingSectionGroup,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35">

      <section name="scriptResourceHandler"
      type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35" requirePermission="false"
      allowDefinition="MachineToApplication"/>

      <sectionGroup name="webServices"
      type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35">

    <section name="jsonSerialization"
      type="System.Web.Configuration.ScriptingJsonSerializationSection,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35" requirePermission="false"
      allowDefinition="Everywhere" />

      <section name="profileService"
      type="System.Web.Configuration.ScriptingProfileServiceSection,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35" requirePermission="false"
      allowDefinition="MachineToApplication" />

      <section name="authenticationService"
      type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35" requirePermission="false"
      allowDefinition="MachineToApplication" />

      </sectionGroup>
      </sectionGroup>
      </sectionGroup>

  2. Within the <system.web> element, locate the <pages> element and insert the following snippet:

    <controls>
      <add tagPrefix="asp" namespace="System.Web.UI"
      assembly="System.Web.Extensions, Version=1.0.61025.0,
      Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </controls>

    EDIT: Thanks to Hardik Bhilota for pointing out that I was missing a comma after the version number. Cheers

  3. Within the <assemblies> element, insert the following snippet:

    <add assembly="System.Web.Extensions, Version=1.0.61025.0,
    Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

  4. Within the <httpHandlers> element, insert the following snippet:

    <add verb="*" path="*.asmx" validate="false"
    type="System.Web.Script.Services.ScriptHandlerFactory,
    System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35"/>

    <add verb="*" path="*_AppService.axd" validate="false"
    type="System.Web.Script.Services.ScriptHandlerFactory,
    System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35"/>

    <add verb="GET,HEAD" path="ScriptResource.axd"
    type="System.Web.Handlers.ScriptResourceHandler,
    System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35" validate="false"/>

  5. Within the <httpModules> element, add the following snippet:

    <add name="ScriptModule"
    type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
    Version=1.0.61025.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35"/>

  6. And since we need to ensure that the assembly is trusted, locate the <SafeControls> element ad add the following snippet:

    <SafeControl Assembly="System.Web.Extensions,
    Version=1.0.61025.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI"
    TypeName="*" Safe="True" />

  7. Within the <configuration> element, add the following snippet:

    <system.web.extensions>
      <scripting>
        <webServices>
        <!-- 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=1.0.61025.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=1.0.61025.0,
        Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

        <add name="ScriptHandlerFactoryAppServices" verb="*"
        path="*_AppService.axd" preCondition="integratedMode"
        type="System.Web.Script.Services.ScriptHandlerFactory,
        System.Web.Extensions, Version=1.0.61025.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=1.0.61025.0,
        Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </handlers>
    </system.webServer>

You're all set

Save your web.config file, restart IIS (iisreset.exe for convenience) and enjoy your ASP.NET 2.0 AJAX 1.0 support in SharePoint.
This isn't a big deal to accomplish, so that's all you get from this blogpost.

In the next blogpost I'll talk about how you can easily create a UserControl, hosted with the SmartPart, with support for AJAX.

 
Posted on 4-Jan-08 by Zimmergren
120 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
Tags: AJAX, MOSS 2007, SharePoint, WSS 3.0
 

Links to this post (Trackbacks/Pingbacks)

Comments

Tuesday, 5 Aug 2008 11:15 by Charles Steinhardt
This articls is unbelievably helpful. I really have a strange problem with SmartPart in SharePoint. Something isn't working for me. I setup the web.config as suggested and made a simple SmartPart / UserControl that has - ScriptManager - UpdatePanel and inside the UpdatePanel is a ListBox and label. I have hooked up the ListBox SelectedIndexChanged to update the label with the current time. In SharePoint, I dropped the SmartPart (not the one with Ajax - the Ajax one just gives me an unspecified error) and added my UserControl. Problem is it works ONLY when you first select an item but then never again until you completely refresh the page and again... only the first time you click on the listbox control. Any ideas or pointers to solve this would be appreciated? I am ready to give up and just code in ASP.NET (where the control works fine)

Wednesday, 6 Aug 2008 09:41 by Tobias Zimmergren
Giving up is not a term used regularly in my vocabulary, Charles. Let's give it a try. First check: Did you set the .AutoPostback = true; to your DropDownList?

Thursday, 21 Aug 2008 04:40 by Dennis
Awesomeeeeee!! Haha fuck that's great (sorry for french).. Works like charm!

Monday, 1 Sep 2008 11:38 by Derek Washington
works wonders. really awesome and good step by step to get it up and running. works like charms

Name:
URL:
Email:
Comments:


MCTS WSS 3.0 (Developer and Administration/Configuration) MCTS MOSS 2007 (Developer and Administration/Configuration) MCP