You must Sign In to post a response.
  • Category: ASP.NET

    How to add webhandler in my ashx using ASP.NET

    Hi experts,
    I am facing an issue, while tried to add webhandler in my .ashx file.

    Here is my handler code:

    <% @ WebHandler language="C#" class="WebUI2.DownHandler" codebehind="DownHandler.cs" %>

    Any solution or suggestion will be most appreciated.

    Thanks
    Sathik
  • #761605
    what problem are you facing while adding handler. is your handler class being derived from the IHttpHandler interface.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #761608
    i can't add webhandler in my .ashx.cs page.

    I'm getting following error:

    The page must have a <%@ webhandler class="MyNamespace.MyClass" ... %> directive
    My code:

    <% @ WebHandler language="C#" class="WebUI2.DownHandler" codebehind="DownHandler.ashx.cs" %>
    using System;
    using System.Web;
    using System.Linq;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections.Generic;
    using System.Web.UI;

    namespace WebUI2

    {



    public class DownHandler : IHttpHandler
    {

  • #761617
    Hi

    <%@ WebHandler Language="C#" Class="MyNamespace.MyClass" %>

    using System;
    using System.Web;

    public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello");
    }

    public bool IsReusable {
    get {
    return false;
    }
    }
    }

    Regards

    Sridhar Thota.
    If you learn from defeat..
    You havent really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • #761623
    Hello Sathik,

    Refer the below code :

    <%@ WebHandler Language="C#" Class="MyWebHandler" %>

    using System;
    using System.Web;

    public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "image/png";
    context.Response.WriteFile("~/Images/Nirav Lalan.png");
    }

    public bool IsReusable {
    get {
    return false;
    }
    }
    }

    Follow the below site for more reference :
    http://www.c-sharpcorner.com/uploadfile/prathore/what-is-an-ashx-file-handler-or-web-handler/

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments