Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:56:38+00:00 2026-06-03T14:56:38+00:00

Using event handlers in my Site-scoped feature’s Feature Receiver, I’m adding my HttpHandler to

  • 0

Using event handlers in my Site-scoped feature’s Feature Receiver, I’m adding my HttpHandler to my configuration (I’m new to this, so the code is a bit disjointed, as I’ve found it here and there).

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

My SharePoint instance’s web.config httpModules section when the feature is not active:

<httpModules>
</httpModules>

And when it is:

<httpModules>
  <add name="SharePointNinjectHttpModule" type="Foo.Bar.SharePointNinjectHttpModule,Foo.Bar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****************" />
</httpModules>

So it seems like the feature receiver event handlers are doing their job (maybe I’m missing something?).

And here’s the 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;
        }

    }
}

The Init() method of my HttpModule never fires. When should I expect it to fire, and why isn’t that happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:56:41+00:00Added an answer on June 3, 2026 at 2:56 pm

    The following change to FeatureActivated() resolved the problem I was having:

    var modification = new SPWebConfigModification("add[@name='SharePointNinjectHttpModule']", "configuration/system.webServer/modules");
    

    I was injecting the module in the wrong section of my web.config.

    Original: configuration/system.web/httpModules
    Changed: configuration/system.webServer/modules

    Once I made the above change, I was correctly adding the httpModule

    Once I was correctly adding the httpModule, my Init() fired immediately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code snippet to add KeyDown event handler to any element
I am not familiar with using event handlers, and I was wondering if anyone
I'm using the below code to receive the messages using serial port event handler.
I have situation where in c# code I am adding an onclick client event
I'm creating a site using drupal where I'd like to prompt my new users
I have an event handler bound to the hover event using the .hover method,
What is the event handler in Java (using net beans, Swing) that resembles the
What is the event handler in Java (using net beans) that resembles the From_Load
When I add event handler to a some elements using query: $('div').mouseover(function () {
When you update DataGridView.DataSource using the assignment operator, the DataSourceChanged event handler is called.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.