让Moss2007支持AJAX

      在web开发中,开发人员经常要考虑到的一个问题就是如何提升用户体验,用户往往最不愿意看到的是他每点击一次按钮/链接,哪怕只是小部分的页面刷新,页面都会持续一段时间的空白,而AJAX的出现正好让有此需求的开发人员眼前一亮。遗憾的是,在SharePoint 2007中本身是不支持AJAX的,我们需要自己动手去配置支持AJAX的环境,希望在下一个版本中能够集成这一功能,下面就如何让您的sharepoint站点支持AJAX功能做些简要说明,以下所讲的内容都是基于.net framework 2.0,如果您的环境是3.5版本的话,请将以下所有xml代码的版本号更改为Version=3.5.0.0

      在配置前,请确保您的机子已经安装过Microsoft ASP.NET 2.0 AJAX Extensions,安装好后就可以按如下步骤进行配置

      1.打开您的sharepoint站点目录下的web.config文件,通常在路径"系统目录\inetpub\wwwroot\Virtual Directories\端口号\"下可以找到,找到<configSections>节点,在该元素内添加下列XML元素 

< 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.找到<system.web>下的<pages>节点,添加下列控件的声明

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

      3.在 <assemblies> 节点内添加对程序集的声明

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

      4.找到 <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" />

      5.在<httpModules>节点内添加以下脚本模块处理程序

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

      6.在<SharePoint> 元素中的 <SafeControls> 节点内声明为安全控件

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

      7.找到<configuration> 节点,添加以下Web 服务处理程序

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

别忘记保存,这样,您的sharepoint站点就能够扩展AJAX的应用了,在下一篇中,将介绍怎样创建支持asp.net ajax的WebPart

你可能感兴趣的:(Ajax)