Parse error with Generic Handler using IIS

11,163

Solution 1

If you are using IIS 7 in pipeline mode then the handler definition must be in <System.webServer> Like this:

<system.webServer>
<handlers>
    <add name="YourImageHandlerName" path="*.ashx" verb="*" type="YourImageHandler" />
</handlers>
</system.webServer>

Check here: http://blogs.msdn.com/b/tmarq/archive/2007/08/30/iis-7-0-asp-net-pipelines-modules-handlers-and-preconditions.aspx

IIS 7.0 has two pipeline modes: integrated and classic. The latter is sometimes referred to as ISAPI mode.

Integrated mode allows both managed and native modules to register for events in the IIS pipeline. This enables many new scenarios, such as applying ASP.NET forms authentication to non-asp.net requests (static files, classic ASP files, etc).

Classic mode is identical to IIS 6.0. In classic mode, the ASP.NET pipeline (BeginRequest, AuthenticateRequest,…, EndRequest) runs entirely within the IIS pipeline’s EXECUTE_REQUEST_HANDLER event. Think of ASP.NET in classic mode as a pipeline within a pipeline.

The other option is to run your site in "classic" mode, in classic mode IIS 7 works like IIS 6 and has the same behaviour (for what matters here) as your Cassini web server.

Hope that help.

Solution 2

You have to add preCondition attribute in web.config file

    <add name="HandlerName" verb="*" path="Handlers/HandlerName.ashx" type="Namespace/HandlerClassName, MyAssembly, Version=1.0.*, Culture=neutral" preCondition="classicMode,runtimeVersionv4.6.1"/>

Its working for my error now.

Share:
11,163
Smur
Author by

Smur

Just another Software Engineer

Updated on June 18, 2022

Comments

  • Smur
    Smur almost 2 years

    What made me curious is that the generic handler works just fine when I'm running the Web App in a Visual Studio ASP.NET Development Server. When I change the config to run it directly from IIS the handler just dies.

    It's an image handler, it writes back an array of bytes to be rendered in an Image object. As I said, it works fine in VS Development Server, but fails on IIS. It doesn't even get called...

    The error I get when I'm trying to call it directly is this:

    Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Could not create type 'YourImageHandler'. Source Error: Line 1: <%@ WebHandler Language="C#" CodeBehind="YourImagehandler.ashx.cs" Class="YourImageHandler" %>

    Handler on web.config:

    <system.web>
        <httpHandlers>
          <add verb="*" path="*.ashx"  type="YourImageHandler"/>
        </httpHandlers>
    </system.web> 
    

    The Generic Handler is in the same assembly of the Web Project, and the whole thing is running on IIS 7.

    • Kirk Woll
      Kirk Woll over 12 years
      What assembly is your handler located in? And is this assembly different from the asp.net web project itself?
    • VoidMain
      VoidMain over 12 years
      How is your handler mapped in web.config? Is it inside &lt;system.web&gt; or inside &lt;system.webServer&gt;? Wich version of IIS are you using?
    • Smur
      Smur over 12 years
      @KirkWoll Answered on the question.
    • Smur
      Smur over 12 years
      @VoidMain Answered on the question.
    • Damith
      Damith over 12 years
      check the application pool .net version of your web site same as your web project .net version or not
    • Kirk Woll
      Kirk Woll over 12 years
      @Felipe, where is YourImageHandler located? What namespace and relative folder?
  • Smur
    Smur over 12 years
    I'll test it tomorrow. Then why did it work when running the app under the Development Server?
  • VoidMain
    VoidMain over 12 years
    It works in your Development server (i assume you are talking about the Cassini version wich ships with VS) because it uses IIS6 syntax.