home *** CD-ROM | disk | FTP | other *** search
-
- <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
-
- <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
-
- <h4>HttpHandlers and Factories</h4>
-
- <div class="indent" style="font-family:Verdana; font-size:8pt;">
- <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b>
- <a class="toc2" target="content" href="#overview">Overview</a><br>
- <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b>
- <a class="toc2" target="content" href="#declaring">Configuring HttpHandlers and Factories</a><br>
- <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b>
- <a class="toc2" target="content" href="#customhandler">Creating a Custom HttpHandler</a><br>
- </div>
-
- <p>
- <hr>
-
-
- <!--BEGIN SECTION-->
- <a name="overview">
- <span class="subhead">Overview</span>
- <p>
-
- ASP+ provides a low-level request/response API that enables developers to use
- NGWS Runtime classes to service incoming HTTP requests. Developers accomplish
- this by authoring classes that support the <b>System.Web.IHTTPHandler</b> interface
- and implement the <b>ProcessRequest()</b> method. Handlers are often useful when
- the services provided by the high-level Page Framework abstraction are not required
- for processing the http request. Common uses of handlers include filters and
- CGI-like applications, especially those that return binary data.
-
- <p>
- Each incoming HTTP request received by ASP+ is ultimately processed by a specific
- instance of a class implementing <b>IHTTPHandler</b>. <b>IHTTPHandler Factories</b> provide the infrastructure
- that handles the actual resolution of URL requests to IHTTPHandler instances.
- ASP+ ships with three standard IHTTPHandler factories - PageFactory,
- RestrictedResourceFactory, and WebServiceFactory.
- Developers can optionally create and register additional factories to support
- richer request resolution and activation scenarios.
-
- <!--BEGIN SECTION-->
- <br>
- <a name="declaring">
- <br>
- <span class="subhead">Configuring HttpHandlers and Factories</span>
- <p>
-
- Http Handlers and Factories are declared in the ASP+ configuration as part
- of a config.web file. ASP+ defines an "httphandlers" configuration section
- where handlers and factories can be added and removed. Settings for
- HttpHandlerFactories are inherited by sub-directories, settings for HttpHandler are NOT
- inherited.
- <p>
-
- ASP+ for example maps all requests for .aspx files to the <b>PageHandlerFactory</b> class in
- top config.web:
-
- <div class="code"><pre>
- <httphandlers>
- ...
- <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
- ...
- </httphandlers>
- </pre></div>
-
- <!--BEGIN SECTION-->
- <br>
- <a name="customhandler">
- <br>
- <span class="subhead">Creating a Custom Http Handler</span>
- <p>
-
- In the following sample a custom <b>HttpHandler</b> is created, which handles
- all requests to "SimpleHandler.aspx" in the respective directory.
- <p>
-
- <Acme:SourceRef
- RunSample="/quickstart/aspplus/samples/apps/handler/simplehandler.aspx"
- ViewSource="/quickstart/aspplus/samples/apps/handler.src"
- Icon="/quickstart/aspplus/images/simplehandler.gif"
- Caption="SimpleHandler"
- runat="server" />
- <p>
-
-
- A custom HTTP handler can be created by implementing the IHttpHandler
- interface, which contains only two methods. By calling <b>IsReusable</b> a
- HTTP factory can query a handler to determine whether the same instance can be used to service multiple requests. The
- ProcessRequest method takes an <b>HttpContext</b> instance as a parameter, which
- gives it access to the <b>Request</b> and <b>Response</b> intrinsics.
- In this sample, request data is ignored and a constant
- string is sent as a response to the client:
-
- <div class="code"><xmp>
- public class SimpleHandler : IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- context.Response.Write("Hello World!");
- }
-
- public bool IsReusable()
- {
- return true;
- }
- }
- </xmp></div>
-
- After placing the compiled handler assembly in the application's /bin directory,
- the handler class can be specified as a target for requests. In this case all
- requests for "SimpleHandler.aspx" will be routed to an instance of the
- SimpleHandler class, which lives in the namespace Acme.SimpleHandler:
-
- <div class="code"><xmp>
- <httphandlers>
- <add verb="*" path="SimpleHandler.aspx" type="SimpleHandler#Acme.SimpleHandler" />
- </httphandlers>
- </xmp></div>
-
- <p>
-
- <h4>Section Summary</h4>
- <ol>
- <li>HTTP Handlers and Factories are the backbone of the ASP+ framework.
- <li>Factories assign each request to one handler, which processes the request.
- <li>Factories and handlers are defined in the config.web file. Settings for factories
- are inherited by sub-directories.
- <li>To create a custom handler, implement IHttpHandler and add the class in the
- httphandlers section of the config.web in the directory.
- </ol>
- <p>
-
- <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-