Implement HTTP requests in ASP. NET

Source: Internet
Author: User

Implement HTTP requests in ASP. NET

It should be noted that not all application Assembly DLL can implement the HTTP Request/response mode. Let's take a look at the description of "Http processing programs and factories" in the Microsoft Asp. Net Quick Start Tutorial:

ASP. NET provides low-level request/response APIs, allowing developers to use the. NET Framework class to provide services for incoming HTTP requests. To this end, developers need to create a class that supports the System. Web. IHTTPHandler interface and ProcessRequest method. The processing program is usually useful when processing HTTP requests without services abstracted by a high-level page framework. Common uses of handlers include filters and CGI-like applications, especially those that return binary data.

Each HTTP request received by ASP. NET is finally processed by a specific instance of the IHTTPHandler class. IHttpHandlerFactory provides the structure for actual resolution of IHttpHandler instance URL requests. In addition to the default IHttpHandlerFactory class provided by ASP. NET, developers can also choose to create and register factories to support a large number of Request Parsing and activation schemes.

From this text, we can see that when the aspx page is not involved. Net Framework provides advanced interface technologies such as data caching, status persistence, Web form control reference, and so on), and the output to the client is not complex HTML text, in particular, you can use one to return binary data slices, sounds, and so on to the client. Cs application file this article uses the c # language, if it is using VB or JScript ,......) The application must have a class that implements the System. Web. IHTTPHandler interface and ProcessRequest. A simple example is as follows:

 
 
  1. Public bool IsReusable
  2. {
  3. Get {return true ;}
  4. }
  5.  
  6. Public void ProcessRequestHttpContext context)
  7. {
  8. HttpResponseRes=Context. Response;
  9.  
  10. Res. Write"<Html><Body>");
  11. Res. Write"<H1>DllTest-Ex1 Example 1)</H1><Hr>");
  12. Res. Write "this page is directly processed by DLL ");
  13. 1 res. Write"</Html></Body>");
  14. }

In the command line status, use the following compilation command to compile ex1.cs into ex1.dll and store it in the bin directory.

Csc/t: library/out: bin \ ex1.dll ex1.cs
Yes, but you need to write the full path.
Csc/t: library/out: j: \ WebSite \ WebTest \ bin \ ex1.dll
J: \ WebSite \ WebTest \ App_Code \ ex1.cs

Add aspx-> dll ing to the configuration file web. config. After adding the map, web. config should be like this:

 
 
  1. <?xml version="1.0"?> 
  2. <configuration> 
  3. <system.web> 
  4. <httpHandlers> 
  5. <add verb="*" path="dlltest1.aspx" type="DllTest.ex1Page,ex1" /> 
  6. </httpHandlers> 
  7. </system.web> 
  8. </configuration> 

Now, when the browser accesses http: // localhost/dlltest/dlltest1.aspx, it actually calls the ProcessRequest method of the DllTest. Ex1Page class in ex1.dll. You can see a simple page during browsing. The preceding section describes how to implement HTTP requests in ASP. NET.

  1. DataList and Repeater controls of ASP. NET
  2. Analysis of IIS ing in ASP. NET
  3. Overview ASP. NET status types
  4. Introduction to ASP. NET and Web servers
  5. EnableViewState attribute of ASP. NET

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.