Integrating ASP.NET Ajax WebPart with SharePoint 3.0
page 5 of 8
by Abdulla Hussein AbdelHaq
Feedback
Average Rating: 
Views (Total / Last 10 Days): 46010/ 68

Extending SharePoint web.config file with Ajax 1.0

Extending SharePoint web.config files with ASP.NET AJAX requires that you interleave some Ajax registration entries in-line with WSS registration entries. To do this you will need to edit your SharePoint web.config file.

1. Add a <sectionGroup>element to the <configSections>tag:

Listing 3

<configSections>    
<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>
</configSections>    

2. Add a <controls> section as a child of the <system.web>/<pages> tag.

Listing 4

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

3. Add the following tag to the <assemblies> tag, within <compilation>.

Listing 5

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

4. Add some new registrations to the end of the <httpHandlers> section.

Listing 6

<httpHandlers> 
      <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"/>
</httpHandlers> 

5. Add a new registration to the HttpModules section beneath any existing registrations.

Listing 7

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

6. Add a SafeControl entry for the System.Web.UI namespace from Microsoft Ajax Extensions, within the <SharePoint>/<SafeControls>section.

Listing 8

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

7. Finally, add the following configuration tags at the bottom of web.config, near the bottom before the end <configuration> tag.

Listing 9

<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. -->
  <p class=Code-GenericCxSpMiddle>      <!--
      <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>

View Entire Article

User Comments

Title: Mr   
Name: Dinesh
Date: 2010-11-15 5:48:03 AM
Comment:
Awesome code and I feel it is the best one for understanding Ajax in Sharepoint. But one small request can u write/give the code in C#. I will be very happy if u do this favor for me. Thanks a lot.
Title: Mr   
Name: James
Date: 2010-10-02 9:57:49 AM
Comment:
Awesome code, and great references too. } Really thumbs up for the code, this is the best tutorial so far!
Will study how all of this works... =)
Title: Mr   
Name: Hiep
Date: 2010-06-18 12:47:50 AM
Comment:
This article is useful. thanks much
Title: Mr   
Name: Jafari
Date: 2009-10-19 8:47:26 AM
Comment:
Thanks Abdulla,
could you explain how to use ajax with multiple updatepanels?
Title: Mr   
Name: ashwin
Date: 2009-02-06 12:54:08 PM
Comment:
Cool stuff
Title: Mr   
Name: Daniel Partridge
Date: 2009-01-21 5:02:39 AM
Comment:
This looks really good!!!!
Title: Dan   
Name: Dan
Date: 2008-12-27 9:45:50 AM
Comment:
Really Liked the oninit code.
Title: mrs   
Name: Madhuri
Date: 2008-12-15 4:32:54 PM
Comment:
This is really very useful. Thanks






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 1:53:58 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search