HOW TO: Create an ASP.NET HTTP handler (from MSDN) using Visual C # .NET (from MSDN)

xiaoxiao2021-03-06  78

The release number of this article has been CHS308001

This article discusses a Beta version of Microsoft products. The information in this article is provided as "as", if there is any change without notice.

For this Beta product, Microsoft does not provide formal product support. For information on getting support for Beta versions, see the documentation included in the beta product file, or view the site you download this version.

For Microsoft Visual Basic .NET versions of this article, see

CHS307997.

This task content

summary

Implementation Processor Deployment Processor Configuration System Test Module Reference

SUMMARY This step-by-step guide demonstrates how to create a simple custom HTTP handler using Visual C # .NET. This article demonstrates how to create, deploy, and configure this handler.

Back to top

Implement a handler

Open Microsoft Visual Studio .NET. In Visual C # .NET, create a class library project called MyHandler. Set a reference to the System.Web.dll assembly. Add the following instructions to this class: use system.Web; rename class synchandler.cs, then change the class definition accordingly. Implement the IHTTPHANDLER interface. Your class definition should be as follows: Public class synchandler: IHTTPHandler implements the IHTTPHANDLER interface of the isreusable property and ProcessRequest method. Because this is a synchronous handler, returning false for the isreusable property so that the handler is not shared. Public Bool IsReusable

{

Get {returnaf false;}

}

Public void processRequest (httpcontext context)

{

Context.Response.write ("Hello from Custom Handler.");

} Compiling the project.

Back to top

Deployment handler

Create a directory called Handler in the C: / INETPUB / WWWROOT directory. Create a bin subdirectory in the newly created Handler directory. The path formed is C: / INETPUB / WWWROOT / HANDLER / BIN. Copy myHandler.dll from the bin / debug directory to the C: / INETPUB / WWWROOT / HANDLER / BIN directory. Follow the steps below to mark the new Handler directory as a web application:

Open Internet Service Manager. Right-click the Handler directory and click Properties. On the Directory tab, click Create. Follow these steps to create an application mapping for the handler. For this handler, create a mapping to the ASPNET_ISAPI.dll file for the * .sync extension. Whenever the request. Sync file, the request will be routed to the ASP.NET, execute the code in the handler by the ASP.NET.

Right click on the Handler web application and click Properties. On the Directory tab, click Configuration. Click Add to add a new mapping. In the Executable Pass box, type the following path: c: /winnt/microsoft.net/framework/ /ASPNET_ISAPI.DLL In the Extension Name box, type .sync. Make sure that the "Check file is existing" check box, then click OK to close the Add / Edit Application Extension Mistup dialog box. Click OK to close the application configuration and handler dialog box. Close Internet Service Manager.

Back to top

Configuration system

In the C: / INETPUB / WWWROOT / HANDLER directory, create a file called web.config. Add the following code to Web.Config:

In the VERB = "*" property, we indicate that the handler processes a request to use any words (such as pos, head, get, etc.). If you want this handler to process only the POST request, change it to VERB = "POST". In the PATH = "*. Sync" attribute, we indicate any incoming request for the handler processing .sync file. In type = "MyHandler.SyncHnder, MyHandler" properties, we indicate that the processing request is implemented in the MyHandler.SyncHandler namespace, and this class resides in the MyHandler program.

Back to top

The test module is tested to test the handler, and there is no need to have a page in the file system. For example, request the default.sync file in the Handler web application (http: // <

Computer name> /Handler/default.sync). You will see the following results:

Hello from Custom Handler.

Back to top

Refer to additional information about the HTTP handler, click the following article number to view the corresponding Microsoft Knowledge Base article:

307985 Beta-info: ASP.NET HTTP MODULES AND HTTP HANDLERS OVERVIEW (Beta-Info: ASP.NET HTTP Module and HTTP Handling Overview)

Back to top

The information in this article applies to:

Microsoft ASP .NET Beta 2 Microsoft Visual C # .NET Beta 2

Reserved: 2001-11-2 (1.0) Keyword KBGRPDSASP KBHOWTO KBHOWTOMASTER KBHTTPRUNTIME KB308001 KBAUDDEVELOPER

转载请注明原文地址:https://www.9cbs.com/read-109062.html

New Post(0)