In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What are the basics of asp.net, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
1. An introduction to the browser-the browser that is browsed by the server Bamp S
The interaction between the browser and the server forms the BPUX S mode on the Internet.
For the HTML to be passed to the server to the server software (IIS), the server software directly reads the static page code, and then returns to the browser
For the ASPX communication server to the server software (IIS) IIS found that it can not handle the aspx files, then go to the mapping table to find the response handler (isapi, server extender) according to the suffix: how does IIS call the extensible program? An extensible program first implements the code according to the excuse provided by IIS, so IIS knows how to call it.
two。 What is asp.net?
! asp.net is a dynamic web technology that runs .net code on the server, dynamically generates HTML, and then responds to a browser
* Note that the main operation is carried out by the server, and the browser only transmits instructions
! You can use JavaScript and Dom to do a lot of work on the browser side, but there are many tasks that can no longer be done on the browser side, such as storing data, accessing the database without complex business logic operations, logic operations with high security requirements, and so on.
! Server controls and HTML controls generate relationships: server controls can be used in aspx pages to simplify openness. However, the browser only recognizes html, so when a page containing server-side controls is requested, the server-side controls in the page will be assembled into corresponding HTML control code strings, such as TextBox:
! asp.net:ASHX (general processor) (the fastest on the server), WebForm,WVC3 (Model, View, Controler)
! The server control is not a new control, and it still generates html tags on the browser side. Although the server control is easy to use, it also has some disadvantages. It is not good to use server controls everywhere.
Common files in 3.aspx.net (key points)
The first small example: dynamic login program
Public void ProcessRequest (HttpContext context) {string modelPath = context.Server.MapPath ("LoginModel.htm"); string htmlSendBack = System.IO.File .ReadAllText (modelPath); context.Response.ContentType = "text/plain"; context.Response.Write (htmlSendBack) If (! string .IsNullOrEmpty (context.Request.Form ["txtName"]) {if (context.Request.Form ["txtName"] = = "zhu" & & context.Request.Form ["txtPassword"] = = "123") {context.Response.Write (" login succeeded! ");} else context.Response.Write (" login failed! ");}}
4. General processor (HttpHandler)
one。 General handler (HttpHandler):
Is a class that implements a special interface to System.Web.IHttpHandler.
Any class that implements the IHttpHandler interface can be used as the target of an external request: (any class that does not implement this interface will not be requested by the browser)
two。 It is called and started to run by a server that supports asp.net. A HttpHandler program is responsible for processing the access request of one or a group of URL addresses corresponding to it, and receiving the access information sent by the client and generating the corresponding content.
three。 We can create our own HttpHandler program to generate browser code to return to the client browser.
4. The HttpHandler program can accomplish most of the tasks that ordinary programs can accomplish:
1. Data and URL parameters submitted by the Lake District client through HTML's Form form
two。 Create response information content to the client
3. Access the file system on the server side
4. Connect to the database and develop database-based applications
5. Call other classes
5. Request the appropriate process
1. The user enters: http://localhost:80777/FirstShower.ashx in the browser address bar
two。 When the server receives the user's request and finds that it is a request .ashx file, it sends the request to framework for execution. Fw finds the corresponding file first.ashx, and returns the generated string (usually in html+css+javascript format) to the browser after execution.
3. The browser receives the data returned by the server, interprets and executes it according to the http syntax, and shows it to the user in the way of interface. (at this point, if the code such as html contains external files, the corresponding file data of the separate request server will be sent again)
6.HTTP request for detailed illustration
7.ashx?-HttpHandler (General processor)
IHttpHandler hander = new page class ()
Hander.ProcessRequest (); / / calls the method in the page class, which is the advantage of the interface
The interpretive language of the ContentType tag put back objects in the web page
Text/html translates in HTML language
Is to set the ContentType property of the response message sent by the server. According to the content of this property, the browser uses different methods to process the response message.
8. Compilation process
1. Each request will create a HttpWorkerRequest and HttpApplication
2.HttpWorkerRequest contains the data in each request message.
The 3.HttpApplication object contains the code to be executed for each request
4. Create a separate HttpApplication object for each request, and all runs for this request are completed in this object
Factory understanding:: HttpApplication pool, every time HttpApplicationFectory will look in this pool to see if there are any free HttpApplication objects, if so, just take them out and create new ones.
What the server does: accept the browser request, create the object of the page class, implement the interface, call the method inside, and return the corresponding thing
HttpRuntime, this class, handles all requests, and it works
1. Parse the request message and encapsulate the message data into an object called HttpWorkerRequest class
two。 Create a HttpContext object. The secondary object is the context of the current request, which contains all the parameter data for processing the request, the most important of which are HttpRequest and HttpResponse (convenient values)
3.HttpRequest mainly contains all the request information, which comes from the HttpWorkRequest object, which contains attributes: Form (customer connection data) QueryString (client url parameter)
4.HttpResponse mainly contains a FileStream object that is used to hold the data to be output to the browser during the execution of the page class.
5. Create the corresponding property in the HttpApplication class object by calling a static method of the HttpApplicationFectory class
6. Because you want to run the ProcessRequest method in the requested page class object in HttpApplication, you need to pass the HttpContext object into the HttpApplication (IHttpHandler hander = create the requested page class object by reflection)?
Execute the ProcessRequest method of HttpApplication (you can think of the execution of this method as a pipeline). In this method, 19 delegated events are executed sequentially.
In the eighth of these events, the object of the requested page class is created
Between 11 and 12, the ProcessRequest method of the created page class is executed
9. How does the server accept and send data?
HTTP Request Response
9.1 Request (HttpRequest) & Response (HttpResponse)
First, how the browser submits data
1 form (data is hidden in the request style, formatted txtname=jamws&txtpwd=123)
2 address bar URL parameter (in the same way as the Get of the form): key value to the browser request attribute http://127.0.0.1/login.ashx?txtname 1=jordan&txtpwd 1: 123
Second, how does the server get the data submitted by the browser?
1 get form data context.Request.Form ["txtname"]
2 get URL parameter: context.Request.QueryString ["txtname1"]
Third, how the server outputs parameters to the browser
Context.Response.Write ("I am the data output from the server to the browser!")
When the user clicks the submit button in the browser, the browser automatically submits the value of the control with name in the form to the server as a [http request message] by assigning a pair of strings.
Request itself can also be seen as all the parameters submitted by a client.
Request.Form contains only the data submitted by the client through post.
Reuqest.QueryString contains only the data submitted by the client through get.
Get: get, take-- when the browser sends a request message to get data from the server, use get
Post: deliver, have, send over. When the browser sends a request message passing parameters, use post
Public void ProcessRequest (HttpContext context) {context.Response.ContentType = "text/html"; System.Text. StringBuilder sbHTML = new System.Text.StringBuilder (); sbHTML.Append ("login page"); sbHTML.Append ("user name:"); sbHTML.Append ("password:"); sbHTML.Append ("Registration"); sbHTML.Append (""); context.Response.Write (sbHTML.ToString ()); / / get the value string strUserName = context.Request.Form passed by browser form post ["txtname"] If (! string .IsNullOrEmpty (strUserName)) {context.Response.Write ("value in Form:" + strUserName);} / / get the value string strUserNameGet = context.Request.QueryString ["txtname"] passed by browser form get; if (! string .IsNullOrEmpty (strUserNameGet)) {context.Response.Write ("value in Url:" + strUserNameGet);}}
9.2 key members of Request (HttpRequest)
The schematic of the redirection is as follows:
-data retention of user controls simulating wubForm-
Public void ProcessRequest (HttpContext context) {context.Response.ContentType = "text/html"; string strNum1 = context.Request.Form ["txtNum1"]; string strNum2 = context.Request.Form ["txtNum2"]; / / determine whether the format is correct string result = "0"; int num1 = 0, num2 = 0; if (! string. IsNullOrEmpty (strNum1) & &! String.IsNullOrEmpty (strNum2)) {if (int.TryParse (strNum1, out num1) & & int.TryParse (strNum2, out num2)) {result = (num1+num2). ToString ();} else {result = "input format error";}} System.Text. StringBuilder sbHTML = new System.Text.StringBuilder (); sbHTML.Append ("calculator"); sbHTML.Append ("+ =
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.