3
Reply

ASP.NET Interview question :- How do we write a HttpHandler ?

    CustomHttp.test is the name of the file that launches the HTTPHandler.

    you need to type the CustomHttp.test filename at the end of the URL and press the enter to start the Custom HTTPHandler.

    First Create a class 


    public class CustomHandler:IHttpHandler
    {
    public bool IsReusable
    {
    get
    { return true; }
    }
    public void ProcessRequest(System.Web.HttpContext context)
    {
    HttpResponse response=context.response;
    Response.Write("<html><body><h2>Sample HTTP Handler</h2></body></html>");
    }

    Do this in web.config file
    <compilation debug="true"/>
    <authentication mode="Windows"/>
    <httpHandlers>
    <add verb="*" path="CustomHttp.test"  type="CustomHTTP.CustomHandler"/>
    </httpHandlers>

    Answer:

    This is a simple a .NET Interview question .Its a two step process.

    First create a class which implements Ihttphandler
     

    public class clsHttpHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }
        public void ProcessRequest(HttpContext context)
        {
           // Put implementation here.
        }
    }

    Step 2 make a entry in the web.config file.

    <httpHandlers>
    <add verb="*" path="*.gif" type="clsHttpHandler"/>
    </httpHandlers>


    You can view my top ASP.NET Interview questions and answers