1. Web application-APS. NET Essence Theory "

Source: Internet
Author: User

1.1.HTTP Protocol

The protocol of the browser and Web server is the application layer protocol, and the Protocol that currently follows the Http/1.1,http protocol is stateless

the client and the server complete a session through the request and response ( Session ), each session, the data sent by both parties is called a message ( Message ), the message is divided into two types:

Request message and response message .

Client Request Message

The client sends an HTTP request to the server with a request message that includes the following format: A request line, a request header (header), a blank line, and four parts of the request data, giving the general format of the request message.

Server Response Message

The HTTP response is also made up of four parts, namely: status line , message header , blank line, and response body .

There are two main layers associated with programmers: the Transport Layer and the application layer .

Transport Layer protocol is responsible for solving the data transmission problem, the transport layer relies on the lower layer of the network to complete the actual data transmission, in the TCP/IP network protocol, the Transport Layer protocol responsible for reliable communication is the TCP protocol. and the network layer is generally implemented by the network driver, the ordinary programmer does not involve; In the TCP/IP protocol, the Network layer protocol is the IP protocol.

1.2 The simplest Web server 1.2.1 network socket socket

Use Socket Development Program, first consider the type of network used, the main three aspects:

    1. Socket type, using the category of the network protocol,the type of IPV4 is pe_inet
    2. types of data communications, common datagrams ( Sock_dgram), Data flow (sock_stream)
    3. the network protocols used, such as: TCP Protocol

On A network address, differentiate between use protocols, assign a number, called Port number (port)0~65535

  1. ( 0 1023 well-known port iana tcp protocol use port complete HTTP Span style= "font-family: Microsoft Jacob Black;" > protocol transfer.
  2. (1024x768~49151) is called the enlistment port and is not controlled by the IANA , but the IANA maintains a registration list.
  3. (49152~65535) is called a dynamic or private port and is used by ordinary users.

in . NET ,system.net provides most of the data types for network programming and common operations

The IPAddress class represents an IP address

The IPEndPoint class represents a combination of an IP address and a port number, called the endpoint of the network

Socket -based data types are available in the System.Net.Sockets namespace

The Socket class encapsulates the operation of the Soket

Common:

Listen: puts the Socket on the listening state and sets the length of the wait queue.

Accept: Create a new Socket for the new connection.

Receive: receives data from the bound Socket.

Send: sends the data to the connected Socket.

1.2.2 TcpListener - based Web server

to simplify based on the TCP protocol Listener,. NET provides the TcpListener class in the System.Net.Sockets namespace , using it, By passing a set of network endpoint information in the constructor, you are ready to listen for parameters without setting the details of the network protocol used , and after invoking the start method, the listener begins. The AcceptTcpClient method blocks the process until a client's connection arrives through hold, which returns a proxy object that represents the client connection, which is of type TcpClient, which can communicate with the client.

1.2.3 HttpListener - based Web server

to further simplify the HTTP protocol Listener, System.Net, provides the HttpListener class. Provides a series of related objects that encapsulate HTTP processing. This class uses the HTTP . SYS system component to do its work, so either Windows XP SP2 or Server 2003 The above operating systems can be used. (Nonsense, in the next admiration with WIN )

1.3 into ASP .

In. NET , the minimum logical unit of Assembly management is the application domain (AppDomain), which can be dynamically loaded into the application domain for. NET programs. However, the assembly after loading cannot be uninstalled separately, only in the application domain as a whole. The application domain provides four important mechanisms:

    • Isolation
    • Unloading
    • Safety
    • Configuration

ASP . Web site applications are hosted in a separate application domain for easy administration. Although you can create a custom application domainthrough system.appdomain, ASP. NET defines a more convenient helper class in the System.Web.Hosting namespace To assist the programmer in creating the application domains involved in the hosted Web server program and setting parameters.

because our application will run in a different application domain than the WEB application, cross-domain issues are involved. the classes that are accessed across domains in. NET must inherit from System.MarshalByRefObject, so our hypervisor will have a proxy object for the remote object that accesses the Web through this proxy object. An object in the application domain.

1.3.1 Web application domain

the static method of the ApplicationHost class Createapplicationhost helps us to create the application domain and set parameters that are required by the WEB application very simply.

1.3.2 Web application Domains are not loaded using the GAC and bin

1.3.3 Unknown Worker object HttpWorkerRequest

the requests that are prepared for processing must be encapsulated as an object of type HttpWorkerRequest, which is an abstract class, defined in the system.web namespace

Public abstract class HttpWorkerRequest

With instances of this class, you must provide the information needed to process the request so that the server can process the request.

1.3.4 Run-time HttpRuntime for WEB applications

The System.Web.HttpRuntime class is the gateway that is processed by the entire ASP.

1.4 Object-formatted HTTP1.4.1 The object type of the request parameter HttpRequest

for each request parameter, HttpRuntime creates an instance of the type Httpreqeuest object in system.web .

This class defines a number of attributes that represent a HTTP request parameters. These parameters are derived from httporkererequest .

1.4.2 The type of object that handles the response HttpResponse

1.4.3 Auxiliary Common tool class HttpServerUtility

1.4.4 encoding and decoding

1.HTML

HtmlEncode encoding, HtmlDecode decoding (General browser completion)

2.URL

The URL string should only appear ASCII characters.

UrlEncode method is used to URL string to encode

3.URL Path

Urlpathencode encode only The Path portion of the URL

4.UrlToken

Urltokenencode used in used when passing a byte array as a string in a URL

1.4.5 Browser type

in the ASP. NET , in the form of an HttpBrowserCapabilities type object, is provided to the developer through HttpRequest.

Public HttpBrowserCapabilities Browser {get; set;}

1. Web application-APS. NET Essence Theory "

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.