. NET learning session, cookies, handwritten Ajax code, and request flow

Source: Internet
Author: User

1.IIS 7 or later integrates two modes, one classic and one integrated (directly integrating the ASP into IIS)

2. What technologies are implemented by the browser and server side? Socket (socket), the syntax of the communication is the HTTP protocol, that is, request messages and response messages

3. The browser request for an ASP. NET page is actually the ProcessRequest method in the requested ASP.

4. When requesting a generic handler, locate the ASHX page background class Ashx.cs, create the class object and invoke the ProcessRequest method, generate the response style, send back to the browser

5.post form submission: Data is delivered in a style of request, formatted like: txtname=james&txtpwd=123

6. The IHttpHandler interface is implemented by the general processing program.
The WebForm background page class inherits from the page class, and the page class implements the IHttpHandler interface

7.WebForm a foreground page file, when first accessed, will be compiled into a class, the class name and the page name is basically the same, except to convert. aspx to _aspx, such as 1.aspx to 1_aspx, the foreground page class inherits from the background page class

8. The HTML code for the entire page is encapsulated in the _render_control method of the foreground page class in cases where the Runatserver attribute is not used in the WebForm entire foreground page

9. About Server.excute//server-side inclusion, such as include Webform2.aspx page in WebForm1.aspx page

The WebForm1.aspx Page_Load event has the following code
Response.Write ("WebForm1.aspx.cs");
Server.Execute ("~/webform2.aspx");

The order of execution at this time is:
WebForm1.aspx.cs
WebForm2.aspx.cs
Webform2.aspx
WebForm1.aspx
Equivalent to the WebForm2 page included in the WebForm1

Status information retention scheme in 10.asp.net
Clients: ViewState, hidden domains, cookies, controlstate, QueryString, where ViewState and controlstate are essentially hidden fields
Server side: Session, Application, Caching, Database

11. A cookie is a server-generated response message header that tells the browser to store cookies on the hard disk, and each time the browser requests the current server, the cookie is generated to the server, and the cookie is sent without the expiration time of the cookie.

12. Set the path to the cookie for access
HttpCookie cookie = new HttpCookie ("username", "AA");
Cookies. Path = "/admin/";//indicates that only pages in the Access Admin folder path Pass cookies
Cookies. Domain = "air.51xieyun.com";//indicates that a cookie is also passed under a level two domain name
Cookies. Expires = DateTime.Now.AddDays (7);//Added cookie expiration time, cookie saved on hard disk, otherwise saved in browser cache
RESPONSE.COOKIES.ADD (cookie);

13..net has a session pool, all sessions are stored in the session pool, each session has a asp.net_sessionid, when the browser sends the request, The server side returns the SessionID as a cookie to the browser and the cookie does not expire, is stored in the browser cache, and the SessionID is sent to the server when the next request is made. The server gets the session from the session pool according to SessionID, and then gets the value stored in the session.

14. If the browser disables cookies, you can write <sessionstate cookieless= "AutoDetect" under the system.web node in Web. config ></sessionState> To allow the cookie to be passed in the form of a URL

15. In the general processing program, if you want to access the session, you must implement the IRequiresSessionState interface, the interface is nothing, is a scalar interface, when the general processing program is requested, The first attempt is to convert the Page class object to an IRequiresSessionState interface object, and if the conversion is unsuccessful, the session object is not loaded, and if the conversion succeeds, the SessionID in the cookie is obtained from the request header, The session object is then found in the session pool of the server, and its reference is assigned to the session property of the Page object according to SessionID.

16. Handwritten AJAX code:

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>    <title></title>    <Scripttype= "Text/javascript">window.onload= function() {document.getElementById ("Btnajaxget"). onclick= function () {                //Creating an Asynchronous object                varXMLHttpRequest= NewXMLHttpRequest (); //Setting ParametersXmlhttprequest.open ("Get", "/handler1.ashx?key=1&a=2"); //let get request not get cache data from browserXmlhttprequest.setrequestheader ("if-modified-since", "0"); //Setting the callback functionXmlhttprequest.onreadystatechange= function () {                    if(Xmlhttprequest.readystate== 4 &&Xmlhttprequest.status==  $) {alert (xmlhttprequest.responsetext); }                }                //sending an asynchronous requestXmlhttprequest.send (NULL); } document.getElementById ("Btnajaxpost"). onclick= function () {                //Creating an Asynchronous object                varXMLHttpRequest= NewXMLHttpRequest (); //Setting ParametersXmlhttprequest.open ("Post", "/handler1.ashx"); //Post does not need this and does not fetch data from the browser cache                //Xmlhttprequest.setrequestheader ("if-modified-since", "0");                //Post requires the Enctype value of this formXmlhttprequest.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); //Setting the callback functionXmlhttprequest.onreadystatechange= function () {                    if(Xmlhttprequest.readystate== 4 &&Xmlhttprequest.status==  $) {alert (xmlhttprequest.responsetext); }                }                //sending an asynchronous requestXmlhttprequest.send ("key=1&a=2"); }        }                   </Script></Head>    <Body>               <inputtype= "button"ID= "Btnajaxget"value= "Ajaxget" />        <BR/>        <inputtype= "button"ID= "Btnajaxpost"value= "Ajaxpost" />    </Body></HTML>
 Public classHandler1:ihttphandler { Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; Context. Response.Write ("Current Time:"+ DateTime.Now.ToString ("YYYY-MM-DD HH:mm:ss") +"key="+ context. request["Key"] +"a="+ context. request["a"]); }         Public BOOLisreusable {Get            {                return false; }        }    }

17.ASP. NET Request IIS Process

18.asp.net General processing program overall operation diagram

19. The server processes the overall page flow, including the page life cycle

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.