Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET handler not running on IIS7

I've wrote a simple handler:

public class ImageHandler : IHttpHandler, IRequiresSessionState
{
    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        byte[] imgData = context.Session["Data"] as byte[];

        if (imgData != null)
        {
            context.Response.CacheControl = "no-cache";
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.ContentType = "image/png";

            context.Response.BinaryWrite(imgData);
            context.Response.Flush();
        }
    }
}

And setup the web.config:

  <system.web>
    <httpHandlers>
      <add verb="GET" path="image.png" type="TestWeb.Handlers.ImageHandler, TestWeb" />
    </httpHandlers>
  </system.web>

  <system.webServer>
    <handlers>
      <add name="Image" verb="GET" path="image.png" type="TestWeb.Handlers.ImageHandler, TestWeb" />
    </handlers>
  </system.webServer>
  • If I run the code allowing VS start a new IIS service and open a new tab it reaches the breakpoint on the handler.
  • If I set don't open a page. Wait for request from an external application it never reaches the handler.

It is not just the breakpoint, no code from the handler executes when I run the website configured on IIS. It only works if I start from VS.

only from VS

What did I miss when configuring IIS7 ?

like image 384
BrunoLM Avatar asked Nov 05 '22 06:11

BrunoLM


1 Answers

I had to switch the Application Pool to Integrated mode, it was using classic.

And I had to remove the handler configuration from <system.web> because it was giving me error 500.23.

HTTP Error 500.23 - Internal Server Error An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

like image 95
BrunoLM Avatar answered Nov 11 '22 16:11

BrunoLM