Saturday, 22 March 2014

What is HTTP Module in

  • What is HTTP Modules?
       HTTP Modules are simple classes that can play themselves into request - processing pipeline.
  • What are method contains in  HTTP Modules ? 
        Crete HTTP Modules, simply create a class that drives from the System.Web.IHTTPModule Interface.
It require to implement two methods, Init & Dispose.
Init - it is primary method you use to implement functionality. It has only one parameter.
public void Init(HttpApplication context
There are some more another methods as below:
  • Authentication Request
  • Authorization Request
  • Begin Request
  • Error
  • Disposed
  • How to create HTTP Modules ? 
         Providing the example how to create HTTP module, the useful and simple code to modify the output stream.
Create a web Project in Visual Studio and add a class to the App_Code Directory.
namespace Sample
    public class AddProcessedMessage : IHttpModule
        private HttpContext _current = null;
        public void Dispose()
            throw new NotImplementedException();
        public void Init(HttpApplication context)
            _current = context.Context;
            context.PreSendRequestContent += new EventHandler(context_PreSendRequestContent);
        void context_PreSendRequestContent(object sender, EventArgs e)
            //Alter the outgoing content by adding a HTML comment
            string message = "";
You need to register it into web config file in configuration section HTTPModule.
    <compilation debug="true" targetFramework="4.0"/>
      <add name="AddProcessedMessage" type="Sample.AddProcessedMessage, App_Code"/>
When application got executed than after processing of the page comment added with datetime.
HTTP Modules are also used for URL rewriting.

URL Re-writings : It is techniques that allow you to intercept the HTTP request & change the path that was requested to an alternative one.

IIS Wild Card - When IIS receives a request to serve a resource , it check if exist than it pass to appropriate handler. IIS than return the results to the Client. If Resource not exist, IIS return 404 file not found error.

 Click on the link for HTTP Processing Pipeline
Click on the link for HTTP Handler

No comments:

Post a Comment