enable feature AJAX of MOSS2007

As default, the feature AJAX of MOSS2007 is disabled, so the site web configuration file should be modified to enable AJAX to achieve the auto complete functionality. The following are steps how to enable it.

Option 1: Modify it manually

step1: Open the web.config file, find out the <configSections> section then fill content out in the section below:

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>

Step2:Find the <pages> section then add the declaration of control below

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

Step3:Add the declaration of the assembly inside <assemblies> section

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

Step4: Add predicate handler in the <httphandlers> section:

 <add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=3.5.0.0, Culture=neutral,  PublicKeyToken=31bf3856ad364e35" validate="false" />
      <add path="*.AppService.axd" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
      <add path="ScriptSource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />

Step5: Add script module inside the <httpModules> section as below:

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

Step6:Add logging configuration inside  <configuration> section:

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,
 Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="C:\trace.log" traceOutputOptions="DateTime" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority:
{priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine:
{localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name:
{localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties:
{dictionary({key} - {value}{newline})}" name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Flat File Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Flat File Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

Option 2: Modify it automaticall by Feature

public class WebConfigModification
    {
        private SPSite _site = null;
        public WebConfigModification(SPSite site)
        {
            this._site = site;
        }
        /// <summary>
        /// open the web.config file, find out the configSections section then fill in the section
        /// </summary>
        private void ModifyConfigSections(Configuration config)
        {
            try
            {
                ConfigurationSectionGroup sectionGroup = config.GetSectionGroup("system.web.extensions");
                if (sectionGroup == null)
                {
                    SystemWebExtensionsSectionGroup topGroup = new SystemWebExtensionsSectionGroup();
                    config.SectionGroups.Add("system.web.extensions", topGroup);

                    ScriptingSectionGroup scriptingGroup = new ScriptingSectionGroup();
                    topGroup.SectionGroups.Add("scripting", scriptingGroup);

                    ScriptingScriptResourceHandlerSection scriptResourceHandler = new ScriptingScriptResourceHandlerSection();
                    scriptingGroup.Sections.Add("scriptResourceHandler", scriptResourceHandler);

                    ScriptingWebServicesSectionGroup webServiceGroup = new ScriptingWebServicesSectionGroup();
                    scriptingGroup.SectionGroups.Add("webServices", webServiceGroup);

                    ScriptingJsonSerializationSection jsonSerialization = new ScriptingJsonSerializationSection();
                    webServiceGroup.Sections.Add("jsonSerialization", jsonSerialization);

                    ScriptingProfileServiceSection profileService = new ScriptingProfileServiceSection();
                    webServiceGroup.Sections.Add("profileService", profileService);

                    ScriptingAuthenticationServiceSection authenticationService = new ScriptingAuthenticationServiceSection();
                    webServiceGroup.Sections.Add("authenticationService", authenticationService);
                    config.Save();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ModifyConfigSectons error :" + ex.Message);
            }
        }

        /// <summary>
        /// find the pages section then add the declaration of control
        /// </summary>
        private void ModifyPagesSection(Configuration config)
        {
            try
            {
                bool prefixExists = false;
                PagesSection pagesSection = (PagesSection)config.GetSection(@"system.web/pages");
                for (int i = 0; i < pagesSection.Controls.Count; i++)
                {
                    TagPrefixInfo prefix = pagesSection.Controls[i];
                    if (prefix.TagPrefix.ToLower().Trim() == "asp" && prefix.Namespace.ToLower().Trim() == "system.web.ui")
                    {
                        prefixExists = true;
                        break;
                    }
                }
                if (!prefixExists)
                {
                    TagPrefixInfo prefixInfo = new TagPrefixInfo("asp", "System.Web.UI", "System.Web.Extensions, Version=3.5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35", "", "");
                    pagesSection.Controls.Add(prefixInfo);
                    config.Save();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("MOdifyPagesSection error: " + ex.Message);
            }
        }

        /// <summary>
        /// add the declaration of the assembly inside assemblies section
        /// </summary>
        private void ModifyAssemblies(Configuration config)
        {
            try
            {
                bool assemblyexists = false;
                CompilationSection compilationSection = (CompilationSection)config.GetSection(@"system.web/compilation");
                AssemblyInfo newAssembly = new AssemblyInfo("System.Web.Extensions, Version=3.5.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35");
                for (int i = 0; i < compilationSection.Assemblies.Count; i++)
                {
                    AssemblyInfo assembly = compilationSection.Assemblies[i];
                    if (assembly.Equals(newAssembly))
                    {
                        assemblyexists = true;
                        break;
                    }
                }
                if (!assemblyexists)
                {
                    compilationSection.Assemblies.Add(newAssembly);
                    config.Save();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ModifyAssemblies error: " + ex.Message);
            }
        }

        /// <summary>
        /// add the declaration of the assembly inside assemblies section
        /// </summary>
        private void ModifyHttpHandlers(Configuration config)
        {
            try
            {
                List<HttpHandlerAction> handlers = new List<HttpHandlerAction>();
                HttpHandlersSection handlersSection = (HttpHandlersSection)config.GetSection(@"system.web/httpHandlers");
                HttpHandlerAction asmxHandlerAction = new HttpHandlerAction("*.asmx", "System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=3.5.0.0, Culture=neutral,  PublicKeyToken=31bf3856ad364e35", "*", false);
                handlers.Add(asmxHandlerAction);

                HttpHandlerAction appServiceHandlerAction = new HttpHandlerAction("*.AppService.axd", "System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", "*", false);
                handlers.Add(appServiceHandlerAction);

                HttpHandlerAction getHeadHandlerAction = new HttpHandlerAction("ScriptSource.axd", "System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", "GET,HEAD", false);
                handlers.Add(getHeadHandlerAction);

                bool handlerActionExists = false;
                foreach (HttpHandlerAction handlerAction in handlers)
                {
                    for (int i = 0; i < handlersSection.Handlers.Count; i++)
                    {
                        if (handlersSection.Handlers[i].Equals(handlerAction))
                        {
                            handlerActionExists = true;
                        }
                    }
                    if (!handlerActionExists)
                    {
                        handlersSection.Handlers.Add(handlerAction);
                        config.Save();
                    }

                }
            }
            catch (Exception ex)
            {
                throw new Exception("ModifyHttpHandlers error: " + ex.Message);
            }
        }

        /// <summary>
        /// add script module inside the httpModules section
        /// </summary>
        private void ModifyModules(Configuration config)
        {
            try
            {
                HttpModulesSection modulesSection = (HttpModulesSection)config.GetSection("system.web/httpModules");
                HttpModuleAction moduleAction = new HttpModuleAction("ScriptModule", "System.Web.Handlers.ScriptModule, System.Web.Extensions,  Version=3.5.0.0, Culture=neutral,   PublicKeyToken=31bf3856ad364e35");

                bool moduleExists = false;
                for (int i = 0; i < modulesSection.Modules.Count; i++)
                {
                    if (modulesSection.Modules[i].Name.ToLower().Trim() == moduleAction.Name.ToLower().Trim())
                    {
                        moduleExists = true;
                    }
                }
                if (!moduleExists)
                {
                    modulesSection.Modules.Add(moduleAction);
                    config.Save();
                }

            }
            catch (Exception ex)
            {
                throw new Exception("MOdifyModules error: " + ex.Message);

            }

        }

        /// <summary>
        /// add safecontrol to the web.config
        /// </summary>
        /// <param name="site"></param>
        private void RegisterSafeControl()
        {
            try
            {
                if (_site != null)
                {
                    SPSecurity.RunWithElevatedPrivileges(() =>
                    {
                        SPWebApplication webApp = _site.WebApplication;

                        // Create a modification
                        SPWebConfigModification mod = new SPWebConfigModification(
                            "SafeControl[@Assembly=\"System.Web.Extensions,  Version=3.5.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35\"][@Namespace=\"System.Web.UI\"]"
                                + "[@TypeName=\"*\"][@Safe=\"True\"][@AllowRemoteDesigner=\"True\"]"
                            , "/configuration/SharePoint/SafeControls"
                            );
                        mod.Owner = "PeopleSearch";
                        mod.Sequence = 0;
                        mod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                        mod.Value = "<SafeControl Assembly=‘System.Web.Extensions,  Version=3.5.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35‘ Namespace=‘System.Web.UI‘ TypeName=‘*‘ Safe=‘True‘ />";

                        // Add the modification to the collection of modifications

                        //bool exists = false;
                        //foreach (SPWebConfigModification modificartion in webApp.WebConfigModifications)
                        //{
                        //    if (modificartion.Name == mod.Name)
                        //    {
                        //        exists = true;
                        //        break;
                        //    }
                        //}
                        //if (!exists)
                        {

                            webApp.WebConfigModifications.Add(mod);
                            webApp.Update();
                            // Apply the modification
                            webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Register SafeControl error: " + ex.Message);
            }
        }

        /// <summary>
        /// modify all
        /// </summary>
        /// <param name="config"></param>
        public void ModifiedToEnableAJAX(Configuration config)
        {
            if (config == null)
            {
                return;
            }
            ModifyModules(config);
            ModifyPagesSection(config);
            ModifyHttpHandlers(config);
            ModifyConfigSections(config);
            ModifyAssemblies(config);
            //RegisterSafeControl();
        }

        public void RemoveSafeControl()
        {
            try
            {
                if (_site != null)
                {
                    SPSecurity.RunWithElevatedPrivileges(() =>
                    {
                        SPWebApplication webApp = _site.WebApplication;
                        Collection<SPWebConfigModification> modsCollection = webApp.WebConfigModifications;
                        SPWebConfigModification configModFound = null;
                        // Find the most recent modification of a specified owner
                        int modsCount1 = modsCollection.Count;
                        for (int i = modsCount1 - 1; i > -1; i--)
                        {
                            if (modsCollection[i].Owner == "PeopleSearch")
                            {
                                configModFound = modsCollection[i];
                            }
                        }

                        // Remove it and save the change to the configuration database
                        modsCollection.Remove(configModFound);
                        webApp.Update();

                        // Reapply all the configuration modifications
                        webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

                    });
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Remove SafeControl error: " + ex.Message);
            }
        }
    }

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = null;

            try
            {
                // Get a reference to the Site Collection of the feature
                if (properties.Feature.Parent is SPSite)
                { site = properties.Feature.Parent as SPSite; }

                if (site != null)
                {
                    string path = site.WebApplication.IisSettings[SPUrlZone.Default].Path.ToString();
                    BackUpConfiguration(path);

                    Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

                    string logConfigPath = string.Empty;
                    var obj = config.AppSettings.Settings["logConfigPath"];
                    if (null != obj)
                    {
                        logConfigPath = obj.ToString();
                    }
                    ConfigLogSettings(path, logConfigPath);
                    //config.SaveAs(Path.Combine(path, fileName), ConfigurationSaveMode.Minimal, true);

                    WebConfigModification modification = new WebConfigModification(site);
                    modification.ModifiedToEnableAJAX(WebConfigurationManager.OpenWebConfiguration("/"));
                }
            }
            catch (Exception ex)
            {
                TraceLog.Error(ex.Message);
            }
        }
}

时间: 2024-11-09 17:57:41

enable feature AJAX of MOSS2007的相关文章

如何用命令行管理SharePoint Feature?

一般情况下对IT管理者来说,在SharePoint Farm中维护Feature,更喜欢使用命令行实现,这样可以省去登录到具体站点的操作.比如IT接到end user的一个需求,要开启Site Collection Feature,如果直接操作就要登录site collection-> Site Setting找到Feature点击执行enable\disable,要是使用命令行直接输入命令和网站会更快捷. 下面我们就以SharePoint2013为例,看下对于Feature的enable.di

怎样用命令行管理SharePoint Feature?

普通情况下对IT管理者来说.在SharePoint Farm中维护Feature,更喜欢使用命令行实现,这样能够省去登录到详细网站的操作. 比方IT接到end user的一个需求,要开启Site Collection Feature,假设直接操作就要登录site collection-> Site Setting找到Feature点击运行enable\disable.要是使用命令行直接输入命令和站点会更快捷. 以下我们就以SharePoint2013为例,看下对于Feature的enable.d

Autotools Mythbuster

Preface Diego Elio?"Flameeyes"?Pettenò Author and Publisher?<[email protected]> SRC=https://autotools.io/index.html David J.?"user99"?Cozatt Miscellaneous Editing?<[email protected]> Copyright ? 2009-2013 Diego Elio Pettenò

A javascript library providing cross-browser, cross-site messaging/method invocation. http://easyxdm.net

easyXDM - easy Cross-Domain Messaging easyXDM is a Javascript library that enables you as a developer to easily work around the limitation set in place by the Same Origin Policy, in turn making it easy to communicate and expose javascript API's acros

CheckBox状态多选

前: 1 <StackPanel Margin="10"> 2 <Label FontWeight="Bold">Application Options</Label> 3 <StackPanel Margin="10,5"> 4 <CheckBox IsThreeState="True" Name="cbAllFeatures" Checked=&qu

Zepto.js详解【好大一篇文章】

参考:Zepto.js API 中文版(1.1.6) 下载 浏览器支持 模块 Change Log Acknowledgements Core $() $.camelCase $.contains $.each $.extend $.fn $.grep $.inArray $.isArray $.isFunction $.isPlainObject $.isWindow $.map $.parseJSON $.trim $.type add addClass after append appen

基于apache-httpclient 4.3封装的HttpUtils

说实话,我的文笔并不好,但是我有一颗热爱代码热爱技术的心.废话少说,言归正传.在做项目时,测试http接口时,总免不了需要请求服务器,但是这个过程用java原生写还是比较复杂的.即使现在有了apache-httpclient,但是对于一些比较复杂的操作还是有些麻烦,然后为了简化代码是提高开发效率,就基于httpclient4.3封装了这么两个工具类.直接上代码: HttpUtils类,很简单,就是用来请求服务器的 import java.io.File; import java.io.FileI

程序包编译安装

一.几个概念 1.开放源码 程序代码,人类可能读懂的程序语言,但是计算机不能识别和执行: 2.编译程序 将程序代码翻译成计算机可以识别的语言: 3.二进程程序 经过编译程序翻译后得到的可以被执行的程序文件. 二.编译源程序的步骤 1.configure 检测程序,并生成makefile文件,其检测的内容如下: 是否有适合的编译程序: 是否有本软件所需的函数库或其他需要的相关软件: 操作系统平台是否支持些软件: 内核的头定义文件是否存在. configure脚本的使用: 1)获取帮助 ./conf

MPS添加管理设备实例NS的过程

MPS添加管理设备实例NS的过程 MPS添加实例NS设备节点: Jan 25 18:25:05 <local0.info> mpsvpx mas_service: 192.168.195.95 01/25/2018:10:25:05 GMT : GUI CMD_EXECUTED : User nsroot - Remote_ip 192.168.195.1 - Command "add_device managed_device user_driven=true,ping_state