Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • HTTP Modules

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 40
    Comment on it

    HTTP Modules are another way of handling any request or any error by the user . It also helps us to handle wrong request and errors in a customized manner.


    Add the following code to ASP.NET Module


    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(OnBeginRequest);
        context.EndRequest += new EventHandler(OnEndRequest);
    }
    void OnEndRequest(object sender, EventArgs e)
    {
        HttpApplication appObject = (HttpApplication)sender;
        HttpContext contextObject = appObject.Context;
        // PageHeaderText is a constant string defined elsewhere
        contextObject.Response.Write("<table width='100%' border='2'><tr><td align='center' background='Gray'>The last event in the HTTP pipeline chain of execution</td></tr></table>");
    }
    void OnBeginRequest(object sender, EventArgs e)
    {
        HttpApplication appObject = (HttpApplication)sender;
        HttpContext contextObject = appObject.Context;
        // Add custom header to the HTTP response
        contextObject.Response.AppendHeader("Author", "Himanshu Joshi");
        // PageHeaderText is a constant string defined elsewhere
        contextObject.Response.Write("<table width='100%' border='2'><tr><td align='center' background='Gray'>HTTP pipeline begins to process the
    request</td></tr></table>");
    }
    


    And then add the httpmodule tag in Web.Config file

    <system.web>
          <httpModules>
          <add name="MyFirstModule"
               type="Himanshu.SampleModule, SampleModuleAssembly"/>
        </httpModules>
    </system.web>
    
    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: