Share via

@ WebHandler

Defines attributes and compilation options for HTTP handler (.ashx) files.

<%@ WebHandler attribute="value" [attribute="value"...] %>


  • Class
    Specifies the name of the class that will be dynamically compiled when the handler is requested. This value can reference any class that inherits from IHttpHandler and can include a fully qualified class name.

  • CodeBehind
    Specifies the name of the compiled file that contains the class associated with the handler. This attribute is not used at run time.


    This attribute is included for compatibility with previous versions of ASP.NET.

  • CompilerOptions
    Specifies a string containing options used to compile the handler. In C# and Visual Basic, this is a sequence of compiler command-line switches. For more information about compiler options, see C# Compiler Options and Visual Basic Command-Line Compiler.

  • Debug
    true if the handler should be compiled with debug symbols; otherwise, false. Because this setting affects performance, set the attribute to true only during development.

  • Description
    Provides a text description of the handler. This value is ignored by the ASP.NET parser.

  • Language
    Specifies the language used when compiling all code within the handler. Values can represent any .NET Framework language, including Visual Basic, C#, or JScript. Only one language can be used per handler.

  • WarningLevel
    Indicates the compiler warning level at which you want the compiler to treat warnings as errors, thus halting compilation of the handler. Possible warning levels are 0 through 4. For more information, see the WarningLevel property.


This directive is valid only in files used as HTTP handlers. By default, ASP.NET treats files with the .ashx file name extension as handlers.


If you do not want to use the .ashx file name extension for your handlers, you can create a handler as a standard class (a .cs or .vb file) that implements the IHttpHandler interface. A handler class file does not require the @ WebHandler directive. You must then register your preferred file name extension with ASP.NET. For details, see How to: Register HTTP Handlers.

You can include only one @ WebHandler directive per file. You can define only one Language attribute per @ WebHandler directive, because only one language can be used per handler.


The @ WebHandler directive has a number of attributes in common with other directives that apply to an entire source file, such as the @ Page directive which is used in .aspx files for Web pages.

To define multiple attributes for the @ WebHandler directive, separate each attribute/value pair with a single space. Do not include a space on either side of the equal sign (=) that connects the attribute with its value.


The following code example instructs the ASP.NET page compiler to use Visual Basic as the inline code language and specifies a class name.

<%@ WebHandler Language="VB" Class="MyTestHandler" %>

See Also


Text Template Directive Syntax

@ Page




HTTP Handlers and HTTP Modules Overview