Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint 2010 我的新HttpModule的Init()方法何时启动?_Sharepoint 2010_Httpmodule_Init_Feature Receivers - Fatal编程技术网

Sharepoint 2010 我的新HttpModule的Init()方法何时启动?

Sharepoint 2010 我的新HttpModule的Init()方法何时启动?,sharepoint-2010,httpmodule,init,feature-receivers,Sharepoint 2010,Httpmodule,Init,Feature Receivers,在我的站点范围功能的功能接收器中使用事件处理程序,我正在将我的HttpHandler添加到我的配置中。我是这方面的新手,因此代码有点脱节,正如我在这里和那里发现的那样 public override void FeatureActivated(SPFeatureReceiverProperties properties) { var site = (SPSite)properties.Feature.Parent; var webApp = site.WebApplication

在我的站点范围功能的功能接收器中使用事件处理程序,我正在将我的HttpHandler添加到我的配置中。我是这方面的新手,因此代码有点脱节,正如我在这里和那里发现的那样

public override void FeatureActivated(SPFeatureReceiverProperties properties) {
    var site = (SPSite)properties.Feature.Parent;
    var webApp = site.WebApplication;
    if (!webApp.IsAdministrationWebApplication) {
        var modification = new SPWebConfigModification("add[@name='SharePointNinjectHttpModule']", "configuration/system.web/httpModules");
        modification.Owner = "addSharePointNinjectHttpModule";
        modification.Sequence = 0;
        modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
        modification.Value = @"<add name=""SharePointNinjectHttpModule"" type=""Foo.Bar.SharePointNinjectHttpModule,Foo.Bar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****************"" />";
        webApp.WebConfigModifications.Add(modification);
        try {
            webApp.WebService.ApplyWebConfigModifications();
            webApp.Update();
        }
        catch (SecurityException e) {
            // todo ApplyWebConfigModifications throws "Access Denied" SecurityException when activating via Site Settings
        }
    }
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
    var site = (SPSite)properties.Feature.Parent;
    var webApp = site.WebApplication;
    if (!webApp.IsAdministrationWebApplication) {
        var oCollection = webApp.WebConfigModifications;
        var iStartCount = oCollection.Count;
        for (int c = iStartCount - 1; c >= 0; c--) {
            SPWebConfigModification oModification = oCollection[c];
            if (oModification.Owner == "addSharePointNinjectHttpModule") {
                oCollection.Remove(oModification);
            }
        }

        if (iStartCount > oCollection.Count) {
            try {
                webApp.WebService.ApplyWebConfigModifications();
                webApp.Update();
            }
            catch (SecurityException e) {
                // todo ApplyWebConfigModifications throws "Access Denied" SecurityException when deactivating via Site Settings
            }
        }
    }
}
当功能未激活时,我的SharePoint实例的web.config httpModules部分:

<httpModules>
</httpModules>
如果是:

<httpModules>
  <add name="SharePointNinjectHttpModule" type="Foo.Bar.SharePointNinjectHttpModule,Foo.Bar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****************" />
</httpModules>
因此,功能接收器事件处理程序似乎正在完成他们的工作,也许我遗漏了什么

这是HttpModule:

using System;
using System.Web;
using Foo.Bar.Models;
using Ninject;

namespace Foo.Bar {
    public class SharePointNinjectHttpModule : IHttpModule {
        public void Init(HttpApplication context) {
            if (Kernel == null) {
                Kernel = new StandardKernel();
                Kernel.Bind<IRepository>().To<Repository>();
            }
        }

        public static IKernel Kernel { get; private set; }

        public void Dispose() {}

        private static IKernel GetKernel() {
            IKernel result = new StandardKernel();
            result.Bind<IRepository>().To<Repository>();
            return result;
        }

    }
}

我的HttpModule的Init方法从不激发。我应该期望它什么时候启动,为什么没有呢?

对FeatureActivate的以下更改解决了我遇到的问题:

var modification = new SPWebConfigModification("add[@name='SharePointNinjectHttpModule']", "configuration/system.webServer/modules");
我在web.config的错误部分注入了模块

原件:configuration/system.web/httpModules 更改:配置/system.webServer/modules

完成上述更改后,我正确地添加了httpModule

一旦我正确添加了httpModule,我的Init立即启动