How do i Deploy HttpHandlers in asp.net 2.0

1.5k Views Asked by At

Question:

How does one deploy a HttpHandler in asp.net 2.0?

Updated Http Handler code (Inside App_Code):

namespace Samples
{
    public class SampleHandler : IHttpHandler
    {    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }

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

Updated Web.Config file

  <system.web>
    <httpHandlers>
      <add verb="*" type="Samples.SampleHandler" path="*.js"/>
    </httpHandlers>
  </system.web>

aspx page

<script type="text/javascript" src="scripts/sample.js"></script>

as you see every javascript request must be routed to the http handler but it doesn't.

2

There are 2 best solutions below

5
On BEST ANSWER

You may take a look at the following guide.

0
On

To get asp.net to respond to requests for filetypes that are not asp.net specific ones you need to ensure that a wildcard mapping has been configured (first part of article). This ensures that IIS passes requests for files ending in .js to asp.net so your custom handler will be called.