. NET Foundation (+) ASP NET application development

Source: Internet
Author: User
Tags rfc asp net

Asp. NET WebForm related content is a bit out of date, but in many of the old projects are still webform, these are legacy issues, the new projects are basically MVC, in the latest version of Microsoft's ASP has been used by default MVC. See Introduction to ASP. NET 5

ASP NET Application Development Foundation
1 Please explain the form of ASP net running
2 What are the common HTTP code
3 What is the difference between a GET request and a POST request
4 Introduction to ASP NET page life cycle

Controls and Pages
1 What is a static page and what is a dynamic page
2 Please briefly describe the function and implementation mechanism of ViewState
3 Session What are the different ways of storage, and how to set
4 Several methods to implement the page jump are listed, and the implementation mechanism is explained.
5 please explain the function and implementation mechanism of <%# Eval ("source") "%>"
6 What is the effect of the ObjectDataSource control

ASP NET Application Development Foundation
1 Please explain the form of ASP net running

Asp. NET is run as an ISAPI filter, and it is the host of a. NET CLR, enabling the ability to run managed server code.


2 What are the common HTTP code

HTTP code is a status code that the server returns to the requesting side in the HTTP protocol

200– Server successfully returned page 404– requested page does not exist 503– service is not available
1XX (Temporary response)
A status code that represents a temporary response and requires the requestor to continue the operation.

Code description
100 (continued) The requesting person shall continue to make the request. The server returns this code to indicate that the first part of the request was received and is waiting for the remainder.
101 (switching protocol) The requestor has asked the server to switch protocols, and the server has confirmed and is ready to switch.

2XX (Success)
Represents the status code that successfully processed the request.

Code description
200 (success) The server has successfully processed the request. Typically, this indicates that the server provided the requested Web page.
201 (created) The request was successful and the server created a new resource.
202 (accepted) the server has accepted the request but has not yet processed it.
203 (non-authoritative information) the server has successfully processed the request, but the information returned may be from another source.
204 (no content) the server successfully processed the request, but did not return any content.
205 (reset content) the server successfully processed the request, but did not return any content.
206 (partial) The server successfully processed a partial GET request.

3XX (redirected)
Indicates that further action is required to complete the request. Typically, these status codes are used for redirection.

Code description
300 (multiple options) for requests, the server can perform a variety of operations. The server can select an action based on the requestor (user agent) or provide a list of actions for the requestor to select.
301 (permanently moved) The requested page has been permanently moved to a new location. When the server returns this response (a response to a GET or HEAD request), the requestor is automatically forwarded to the new location.
302 (Temporary move) The server is currently responding to requests from a Web page in a different location, but the requestor should continue to use the original location for future requests.
303 (View other locations) The server returns this code when the requestor should use a separate GET request for the different locations to retrieve the response.
304 (not modified) The requested webpage has not been modified since the last request. When the server returns this response, the Web page content is not returned.
305 (using a proxy) the requestor can only use the proxy to access the requested Web page. If the server returns this response, it also indicates that the requestor should use the proxy.
307 (Temporary redirect) The server is currently responding to requests from a Web page in a different location, but the requestor should continue to use the original location for future requests.

4xx (Request error)
These status codes indicate a possible error in the request and hinder the processing of the server.

Code description
400 (Error request) The server does not understand the syntax of the request.
401 (unauthorized) request authentication is required. The server may return this response for pages that need to log on.
403 (Forbidden) The server rejects the request.
404 (not found) The requested Web page was not found by the server.
405 (method Disabled) Disables the method specified in the request.
406 (not accepted) cannot use the requested content attribute to respond to the requested Web page.
407 (requires proxy authorization) This status code is similar to 401 (unauthorized), but specifies that the requestor should authorize the use of the proxy.
408 (Request timed out) A timeout occurred while the server was waiting for a request.
409 (conflict) The server has a conflict when it finishes the request. The server must include information about the conflict in the response.
410 (Deleted) If the requested resource has been permanently deleted, the server returns this response.
411 (requires valid length) The server does not accept requests that do not contain a valid Content-Length header field.
412 (precondition not met) the server does not meet one of the prerequisites set by the requestor in the request.
413 (Request entity too Large) The server cannot process the request because the request entity is too large to exceed the processing power of the server.
414 (The requested URI is too long) The requested URI (usually the URL) is too long for the server to process.
415 (Unsupported media type) The requested format is not supported by the requested page.
416 (The request scope does not meet the requirements) if the page cannot provide the requested scope, the server returns this status code.
417 (unmet expectations) the server does not meet the requirements for the expected Request header field.

5XX (server error)
These status codes indicate that the server has an internal error while trying to process the request. These errors may be the error of the server itself, not the request.

Code description
500 (server internal error) the server encountered an error and could not complete the request.
501 (not yet implemented) the server does not have the capability to complete the request. For example, this code may be returned when the server does not recognize the request method.
502 (Error Gateway) The server receives an invalid response from the upstream server as a gateway or proxy.
503 (Service Unavailable) the server is not currently available (due to overloading or downtime maintenance). Typically, this is only a temporary state.
504 (Gateway Timeout) The server acts as a gateway or proxy, but does not receive requests from the upstream server in a timely manner.
505 (HTTP version not supported) the HTTP protocol version used in the request is not supported by the server.


RFC 6585 released 4 new HTTP status codes.

is the HTTP protocol still changing? Yes, the HTTP protocol has been evolving, and the new status code is useful for developing REST services or HTTP-based services, and we'll give you a detailed description of the four new status codes and whether you should use them.
428 Precondition Required (prerequisites required)

A prerequisite is when a client sends an HTTP request that must meet some preset criteria if it wants the request to succeed.

A good example is the If-none-match header, which is often used in GET requests, and if If-none-match is specified, then the client receives the response only after the ETAG in the response has changed.

Another example of a prerequisite is the If-match header, which is typically used on PUT requests to indicate that only resources that have not been changed are updated, which is used to prevent the same content from being overwritten by multiple clients using HTTP services.

When the server side uses the 428 precondition Required status code, it means that the client must send the above request header to execute the request, which provides an effective way for the server to prevent the ' lost update ' issue.
429 Too Many requests (too many requests)

This status code is useful when you need to limit the number of clients requesting a service, which is the request speed limit.

Prior to this, there were some similar status codes, such as ' 509 Bandwidth Limit exceeded '. Twitter uses 420 (this is not an HTTP defined status code)

If you want to limit the number of client requests to a service, you can use a 429 status code and include a retry-after response header to tell the client how long it will take to request the service again.
431 Request Header Fields Too Large (header field too large)

In some cases, the client sends the HTTP request header to become very large, then the server can send 431 request header fields Too Large to indicate the problem.

I am not quite sure why there is no 430 status code, but jump straight from 429 to 431, I try to search but no results. The only guess is 430 Forbidden and 403 Forbidden too like, in order to avoid confusion to do so, God knows!
511 Network authentication Required (authentication required)

This status code is interesting to me, and if you're developing an HTTP server, you don't have to deal with that status code, but if you're writing an HTTP client, the status code is very important.

If you use laptops and smartphones frequently, you may notice that a large number of public WIFI services require you to accept some protocols or you must log in before you can use them.

This is annoying by intercepting HTTP traffic and returning a redirect and login when a user tries to access the network, but this is the case.

With these "intercept" clients, there are some nasty side effects. Examples of these two are mentioned in the RFC:

If you visit a website before you log in to WiFi, the network device will intercept the first request, and these devices often have their own website icon ' Favicon.ico '. After logging in, you will find that the website icon you visited for a while has been the icon of the WiFi login website.
If a client uses an HTTP request to find a document (possibly JSON), the network responds to a login page so that your client resolves the error and causes the client to run the exception, which is a common problem in reality.

So the 511 status code is proposed to solve this problem.

If you are writing an HTTP client, you might want to check the 511 status code to verify that authentication is required before you can access it.

The above about HTTP code comes from http://www.cnblogs.com/shanyou/archive/2012/05/06/2486134.html

These things do not use the back, the return of the numbers to find out.


3 What is the difference between a GET request and a POST request

    • Design goals are different. When the HTTP protocol is designed, get acts as a request for resources to the server, while post acts as a request to send data to the server.
    • When a GET request submits data to a form, it is added to the URL, in the following form: [Key]=[value], and data and data are separated by &. The post request, in turn, puts the data directly into the request body of the HTTP request. The URL of a GET request contains not only the server URL, but also the form data, and the URL of the post contains only the URL of the server.
    • The HTTP protocol limits the length of a GET request without limiting the length of the POST request.
    • The HTTP protocol restricts the data set for GET requests to use ASCII characters, while post can use the entire ISO10646 character set.
    • For ASP., when you create a new form, the default request is post.


4 Introduction to ASP NET page life cycle

The best way to understand the life cycle of a page is to actually visit the page and track its actual experience by adding the trace attribute to the page definition.

<%@ Page Language="C #"AutoEventWireup="true"CodeFile="TestPost.aspx.cs"Inherits="Testpost"Trace="true"  %>

If you classify the steps of the ASP. NET page life cycle, it can be broadly divided into 4 categories:

    • Initialization
    • Loading data and Pages
    • Triggering events
    • Hold status and Render page

1) Initialization

Initialization includes PreInit, Init, and initcomplete Three steps, which include features such as initializing class objects, initializing the principal page, and determining if initial functions such as the first access page are available.

2) Loading data and pages

This category contains steps such as LoadState, Processpostdate, preload, Load, Processpostdata (second), and so on.

The ViewState object is loaded first from the data that is returned from the page, and all the data is passed to the server in Base64 encoding with the page. It then starts processing the callback data, which is the key-value pairs in the form that are stored in the object. The page is then loaded, and programmers typically do some initialization programming here, such as writing page initialization code in the OnLoad event. Finally, the processpostdata is executed again to process the load when new data is added.

Two executions of processpostdata are required, and the first processing ensures that all data is read from the page before the page is executed, so that the data can be accessed when the page is loaded. The second processpostdata is to make the page load the data in the newly created control can be processed.

3) Trigger Event

The trigger event contains the changedevents and postbackevent steps. This first compares the data in the viewstate with the data from the last postback of the page, and feels that those events need to be triggered, where the events are triggered one by one, but the order cannot be determined. Then check to see if the post back event is triggered, which is the event that the page submits.

4) Save status and Render page

This will include SaveState, Savestatecomplete, and render steps. First, the page encodes all of the viewstate data and embeds it in a hidden control on the page. It then transforms all the control labels and generates the page HTML and sends back to the client.

The above classification does not contain the unload step, which is because this step is important, but never requires the programmer to care about ASP. NET is responsible for releasing resources for all objects.

Asp. NET page declaration cycles include: PreInit, Init, InitComplete, LoadState, Processpostdata, preload, Load, Processpostdata (second time), changeevents , Postbackevent, LoadComplete, PreRender, Prerendercomplete, SaveState, Savestatecomplete, Render, Unload these steps.


Controls and Pages
1 What is a static page and what is a dynamic page

Static pages are pages that do not require additional processing of server code and can be presented directly to the user, and a common static page is an HTML page. In contrast, a page that requires server code to handle each request is called a dynamic page, ASP. The most common dynamic pages in net are aspx files.


2 Please briefly describe the function and implementation mechanism of ViewState

ViewState is used to store data within a page range to ensure the continuity of data before the user leaves the page. On the implementation, viewstate is stored inside a hidden control within the page and is extracted for use after it is submitted to the server.


3 Session What are the different ways of storage, and how to set

1) saved in the IIS process

This is the process of saving all session data to the running of IIS, that is, Inetinfo.exe. This is the default session storage method, which is often the most commonly used. This storage feature is that session data access is relatively fast because there is no need for additional cross-process interaction. However, when the IIS process crashes or restarts, the session information is permanently lost.

Asp. NET default setting is to save session data in the IIS process, which is shown here for illustrative purposes. All you have to do is set the session Save method in the Web. config file:

  < system.web >    <  mode= "InProc"  timeout= "></"sessionstate  >  </system.web>

2) Save on the status server

refers to storing session data in a process known as the ASP. NET State Service, which is a separate process separate from the ASP. NET worker process or IIS application pool. Use this mode to ensure that session state is preserved when the Web application is restarted and that the session state is available to multiple Web servers on the network.

In order for ASP to put the session data into the state server, the programmer first needs to prepare a state server. In the service, you can find an ASP. NET State Service, which is the status server provided by ASP. The service is started on a specific server and has a state server.

Next you need to configure the Web. config file:

  < system.web >    <  mode= "StateServer"                   stateconnectionstring= "tcpid= 192.168.0.1:42424 "                  timeout="></sessionstate >  </ system.web >

In this way, all session data is saved in the specified state server and is no longer related to the IIS process.

3) Save in SQL Server database

SQL Server is a Microsoft-provided enterprise database server product that can store session data in a SQL Server database. For such a configuration, the home page needs to prepare the database server, and then run the. NET installed installation Tool installation state database, which is located at a location similar to this: C:\Windows\Microsoft.NET\Framework\v4.0.30319\ Aspnet_regsql.exe

The Setup wizard leads you through the installation of the state server, and then you need to configure the Web. config file and add the database connection string:

    <mode= "SQL Server"                   sqlconnectionstring= "Data source= localhost;integrated Security=sspi; "                   timeout= "></"sessionstate>  </ system.web >

Note: Once you choose to save the session data to the database, you must ensure that all session data is serialized.

4) Custom Save program

This means of preservation provides greater flexibility. For example, a programmer may want to save some session data in a more efficient but less secure way, while storing other sensitive session data in a less efficient but secure way, you can customize a save program and indicate that the program is saving session data.


4 Several methods to implement the page jump are listed, and the implementation mechanism is explained.

Response.Redirect, Server.Transfer, Server.Execute, JS, direct use of hyperlinks.

Response.Redirect is the server that overwrites the HTTP response and forces it to return to the client immediately, and the client receives a response from the server and redirects to the new URL.

Server.Transfer is the server directly to jump, and then return the results to a client, the client does not know.

Server.Execute, when the ASP. NET Server code executes to the Server.Execute method, the execution of the current page is paused, the new page load is executed, and the output response of the new page is obtained. Server.Execute has multiple overloaded versions that can append the results of a new page to the response of the current page, or handle the execution output of a new page manually. As with Server.Transfer, the Server.Execute method can only invoke new pages within the same site.


5 please explain the function and implementation mechanism of <%# Eval ("source") "%>"

The eval expression implements the function of data binding, <%# eval ("source") "%> to obtain the required binding data item from the top of the binding data stack and data binding.


6 What is the effect of the ObjectDataSource control

ObjectDataSource plays the role of passing elements in two-way data binding, which is often used as the intermediate interface between the business logic layer and the page display layer in a layered BS system.

Reprint please specify the source:

Jesselzj
Source: http://jesselzj.cnblogs.com

. NET Foundation (+) ASP NET application development

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.