Custom HTTP Module Init method Executing multiple times RRS feed

  • Question

  • Hello,

    We have a requirement to write the data to custom database for each request. I have created custom HTTP Module to do logging in the DB.

    namespace ABC
        public class XYZ:IHttpModule
    		public void Dispose()
                //throw new NotImplementedException();
    		public void Init(HttpApplication context)
    		context.BeginRequest += context_BeginRequest;
    		void context_BeginRequest(object sender, EventArgs e)
    			// Write data to DB

    And registered my module under SharePoint web.config file. 

    Now the problem is that, my init method is executing multiple times for single page request.

    I want to execute my logic only once for each request. Appreciate any help here.



    Friday, November 27, 2015 4:00 PM


  • Hi Sith,

    Yes, when users access one page in a SharePoint site, there will be at least a request sent to server for the destination page.

    However, as there may be some Ajax requests will be sent in one page(for asynchronous requests), we will see several BeginRequest events to be executed when accessing one single page only.

    In such a scenario, your “context_BeginRequest” method did get executed once a time per request.

    If you want to execute your method only one time when users accessing one single page, you may need to add some logic in your code to detect the current requesting resource and submit data to database accordingly.


    Patrick Liang

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Dennis Guo Sunday, December 6, 2015 1:43 PM
    • Marked as answer by Dennis Guo Tuesday, December 8, 2015 9:36 AM
    Monday, November 30, 2015 8:39 AM