ASP.NET interview question :- How do we write a HttpModule ?

 Posted by articlesmaint on 2/24/2011 | Category: ASP.NET Interview questions | Views: 5290


Again a simple .NET Interview question Writing a HttpModule is a two step process.


Create a class which implements IhttpModule.


 

public class clsHttpModule : IHttpModule
{


    public void Init(HttpApplication
context)
    {
      
this.httpApp = context;
      
httpApp.Context.Response.Clear();
      
httpApp.AuthenticateRequest += new
EventHandler(OnAuthentication);
      
httpApp.AuthorizeRequest += new
EventHandler(OnAuthorization);
 ....
 ....
 ....
  

    }
    void OnAuthorization(object
sender, EventArgs a)
   
{
       
//Implementation
    }
    void
OnAuthentication(object sender, EventArgs a)
   
{
      

       
//Implementation
    }
   
}


Make a entry in the web.config file.


 

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


 


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response