ASP.NET 2.0应用程序添加ASP.NET AJAX 组件引用之web.config配置
[2007.07.06 NC]
前言:ASP.NET 2.0应用程序默认情况下不能引用ASP.NET Ajax 控件,如需引用,则必须配置web.config
参考:《ASP.NET Ajax 程序设计 第I 卷》——配置ASP.NET Ajax
配置步骤:
1、 添加引用
A、System.Web.Extensions. dll
(C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\ v.1.0.61025)
B、Microsoft.Web.Preview.dll
(C:\Program Files\Microsoft ASP.NET\ ASP. NET 2.0 AJAX Futures January CTP\v.1.0.61025)
如需引用ajaxControlToolkit包中的控件,则还需引用AjaxControlToolkit.dll
2、 配置web.config方件
Web.config是实际上XML文档,其根元素为<configuration>
<!--配置asp.net ajax webconfig___1-->
<!--此节点必须作为<configuration>的第一个节点出现-->
<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">
<!--若希望ASP.NET AJAX应用程序在运行时能够对客户端脚本文件进行压缩或缓存,则应该在
<sectionGroup name="scripting>中定义一个新的<section>如下所示-->
<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>
<!--配置asp.net ajax webconfig___2-->
<!—此节点作为<configuration>的一个子节点出现-->
<system.web.extensions>
<scripting>
<webServices>
</webServices>
<!--以下这段声明将在程序运行于Release模式时压缩客户端脚本库的大小。
如果不是程序中有非常特殊的需要,我们绝对应该添加这个HTTP模块以提高网络传输速度-->
<scriptResourceHandler enableCompression="true" enableCaching="true"/>
</scripting>
</system.web.extensions>
<!--配置asp.net ajax webconfig___3-->
<!--在<configuration>根元素中的<system.web>节中注册ASP.NET AJAX服务器端控件的前缀-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions,Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="Microsoft.Web.Preview.UI" assembly="Microsoft.Web.Preview"/>
<add tagPrefix="asp" namespace="Microsoft.Web.Preview.UI.Controls" assembly="Microsoft.Web.Preview"/>
</controls>
</pages>
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies>
<!--配置asp.net ajax webconfig___4-->
<!--修改<compilation>节,允许调试和添加必要的用于调试的程序集-->
<!--上面代码中同样包含了<buildProviders>以及其中*.asbx文件的声明。若应用程序不需要服务器端远程Web Service桥,则没有必要添加<buildProviders>中的这部分内容-->
<!--以下此节为新添加-->
<buildProviders>
<add extension="*.asbx" type="Microsoft.Web.Preview.Services.BridgeBuildProvider"/>
</buildProviders>
</compilation>
<!--配置asp.net ajax webconfig___5-->
在<system.web>节点中添加或者修改<httpHandlers>节点
<!--在<system.web>元素中,若你的ASP.NET AJAX应用程序中需要在客户端调用服务器端的Web Service,则需要对Web Service应用一些新的HTTP Handler,并为其生成必要的客户端JavaScript代理脚本。找到<system.web>元素中的< httpHandlers>子元素,移除现有的Web Service文件(.asmx)的Handler, 然后添加ASP.NET AJAX引入的新的Handler(*.asbx一项同样可以根据需要有选择地添加)-->
<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"/>
<add verb="GET,HEAD,POST" path="*.asbx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<!--配置asp.net ajax webconfig___6-->
<!--仍然是在<system.web>元素中添加如下的HTTP模块声明-->
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<!--配置asp.net ajax webconfig___7-->
<!--在<configuration>节中添加<system.webServer>小节,为Web服务器进行相应的配置(这些配置是可选的,将只应用于IIS7中)-->
<system.webServer>
<validation validateIntegratedModeC/>
<modules>
<add name="ScriptModule" preC 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" preC 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" preC type="System.Web.Script.Services. ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preC verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ASBXHandler" verb="GET,HEAD,POST" path="*.asbx" preC type="System.Web.Script.Services. ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>