How to dispose IHttpModule correctly?

The lifecycle of an HttpModule is tightly integrated with the lifecycle of an HttpApplication. Instances of HttpModule are generated when the application is started and destroyed when the application is disposed of. In this case there is no point in unsubscribing from the event because the publisher (HttpApplication) is being disposed of anyway. Of course, … Read more

How to log request inputstream with HttpModule, then reset InputStream position

I’ve worked out the problem: I think that calling dispose on the StreamReader must be killing the InputStream too. Instead of using the StreamReader I did the following: var bytes = new byte[request.InputStream.Length]; request.InputStream.Read(bytes, 0, bytes.Length); request.InputStream.Position = 0; string content = Encoding.ASCII.GetString(bytes); So the complete code: public class LoggingModule : IHttpModule { public void … Read more

HttpModule Init method is called several times – why?

It’s normal for the Init() method to be called multiple times. When an application starts up, the ASP.NET Worker process will instantiate as many HttpApplication objects as it thinks it needs, then it’ll pool them (e.g. reuse them for new requests, similar to database connection pooling). Now for each HttpApplication object, it will also instantiate … Read more

Why does my nested HttpModule EndRequest event handler not fire?

I also wanted to modify my headers, but i needed to hide as much as possible. It is the same for Add or Remove or both, it is just headers. 1) You can set MvcHandler.DisableMvcResponseHeader = true; in the global.asax protected void Application_Start() { MvcHandler.DisableMvcResponseHeader = true; } and protected void Application_PreSendRequestHeaders() { Response.Headers.Remove(“Server”); Response.Headers.Remove(“X-AspNet-Version”); … Read more

HTTPModule Event Execution Order?

Maybe this helps http://support.microsoft.com/kb/307985/en-us/ An HttpApplication class provides a number of events with which modules can synchronize. The following events are available for modules to synchronize with on each request. These events are listed in sequential order: BeginRequest AuthenticateRequest AuthorizeRequest ResolveRequestCache AcquireRequestState PreRequestHandlerExecute PostRequestHandlerExecute ReleaseRequestState UpdateRequestCache EndRequest The following events are available for modules to … Read more

IHttpHandler vs IHttpModule

An ASP.NET HTTP handler is the process (frequently referred to as the “endpoint”) that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page … Read more

Can I access session state from an HTTPModule?

Found this over on the ASP.NET forums: using System; using System.Web; using System.Web.Security; using System.Web.SessionState; using System.Diagnostics; // This code demonstrates how to make session state available in HttpModule, // regardless of requested resource. // author: Tomasz Jastrzebski public class MyHttpModule : IHttpModule { public void Init(HttpApplication application) { application.PostAcquireRequestState += new EventHandler(Application_PostAcquireRequestState); application.PostMapRequestHandler += … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)