次の方法で共有


Adding ASP.NET AJAX Support to an Existing ASP.NET 2.0 Web Application

I got this question recently so I thought I would post the steps.  I am assuming that you already installed ASP.NET AJAX Extensions 1.0.  If not, you can get find out how to get it here.

The ASP.NET AJAX Web Site template that is available in Visual Studio 2005 after installing ASP.NET AJAX has additional sections added to the default web.config file in addition to the requirement to add a ScriptManager to any page that will have AJAX enabled server controls running.  So, the first step is to add a ScriptManager server control to your page.  If your web applicaiton has a Master Page, consider adding the ScritManager object to the Master Page.  The ScriptManager doesn't output any HTML at run-time so don't worry about where you put it but do make sure it exists on the page before using any of the ASP.NET AJAX server controls like the UpdatePanel.  Next you will need several configuraiton sections to your web.config for the Web Application.  Here are the steps:

1.  Add this section inside of <configuration> to the web.config above <system.web> so that it looks like this:

 

  <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/Edit the <pages> element inside of <system.web> so that it looks like this:

 

    <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. Edit the <compilation>  config section by adding the System.Web.Extensions assembly to  the list:

 

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

 

 

4.   Add/Edit <httpHandler> and <httpModules>  config section inside of  the <system.web> config section:

 

    <httpHandlers>

      <remove verb="*" path="*.asmx"/>

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

 

    <httpModules>

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

    </httpModules>

Add this section below </system.web> inside of </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>

 

5. Add this section to the web.config below the closing </system.web> tag:

 

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

Comments

  • Anonymous
    April 25, 2007
    Are there any modifications required to the machine.config to recognize these new sections?  The video how-tos show using the system.web.extensions as well, and those seem to be IIS 7 specific... alan.jackson@westonsolutions.com

  • Anonymous
    May 09, 2007
    No modifications are necessary to machine.config unless you want to move the entries in web.config listed above into your machine.config (or the root web.config on your web server) in order to have the changes apply to all sites. system.web.extensions is part of the ASP.NET AJAX Extensions RTM release.  You may be using a pre-release version that has microsoft.web.extensions as the namespace.  This link has more details: http://ajax.asp.net/files/Migration_Guide_Beta2_to_RC.aspx -Rob Cameron


RE: Are there any modifications required to the machine.config to recognize these new sections?  The video how-tos show using the system.web.extensions as well, and those seem to be IIS 7 specific... alan.jackson@westonsolutions.com

  • Anonymous
    August 15, 2008
    Why do we use step 5? thanks