locked
Logging Requests using HttpModule RRS feed

  • Question

  • User-305496339 posted
    I am trying to log my requests in MVC. I set breakpoints on the methods but they never fire. I registered my module in the
    web.config file

     

    My code:

    public class MyHttpModule : IHttpModule
        {
            public MyHttpModule() { }
            public void Init(HttpApplication application)
            {
                application.BeginRequest += new EventHandler(this.context_BeginRequest);
                application.EndRequest += new EventHandler(this.context_EndRequest);
            }
            public void context_BeginRequest(object sender, EventArgs e)
            {
                StreamWriter sw = new StreamWriter(@"C:\log.txt", true);
                sw.WriteLine("request began at " + DateTime.Now.ToString());
                sw.Close();
            }
    
            public void context_EndRequest(object sender, EventArgs e)
            {
                StreamWriter sw = new StreamWriter(@"C:\log.txt", true);
                sw.WriteLine("Request Ended at " + DateTime.Now.ToString());
                sw.Close();
            }
            public void Dispose() { }
        }

    <httpModules>
    <add name="MyHttpModule " type="MyHttpModule " />
    </httpModules>



    Monday, March 12, 2018 5:13 AM

Answers