Tag: Handler imp Run ASMX object event ace map up and down
asp: Generic handler. ASHX efficiency is more efficient, WebForm (ASPX) consumes resources, MVC (efficiency is just between the two)
Commonly used files in ASP.
. ASHX general handlers Httphandler,asp.net core programs, but generally use. aspx (often used when you don't need to return a lot of HTML code)
. aspx common program WebForm, a core file for creating Web pages and Web pages for programming (foreground file) (to return a large amount of HTML)
. Aspx.cs is used to write a large number of C # business code and. aspx companion uses
. ascx indicates an ASP. NET user-defined control
. asax event syntax with ASP. NET application-level events
. config configuration file for setting various properties of the application
. asmx for host Web service remote use in local goods
One, General handler processing process (HttpHandler)
IIS cannot handle this suffix program passing the program to ASPNET_ISAPI through a mapping table. DLL, and then forwarded the request to the Web program
The site program calls the static method of the HttpRuntime class to process the request, with the following steps:
1, implements the class of System.Web.IHttpHandle special interface
The class that implements the interface can act as a target program for an external request
2. Create the HttpContext context data contextual object that is used to process the requested parameter data.
(mainly httprequest--> used for form data URL parameters and HttpResponse () mainly contains the data that the FileStream object uses to hold the output)
3, parse the request packet and encapsulate the data to the properties corresponding to the HttpWorkerRequest object
and call the static method in the HttpApplicationFactory class to create the HttpApplication object
(In fact, first through the HttpApplication pool to see if there is no idle to create), then
The object will process all the running procedures for this request
The ProcessRequest method in the page class can be called when the 4,httpcontex object is passed into the HttpApplication
Second, the server requests the data and receives the data
In a generic handler, the System data Object (property) is called through the HttpContext context
How page points to the pages themselves
Request reads the value sent during the client's Web request
Response encapsulates the output of the page execution period returned to the HTTP client
Application state objects acting on the entire program's run time
Session state hold object, used to track a single user's session
A way for a Cookie client to keep session information
Server-raised access to methods and properties on the server
1, two kinds of simple data request and receive way
(Post is passed through the data message (socket), get is through the URL so there is a limited size)
1.1 Through the table only son value form can pass the data to the corresponding page via post and get method
Reception of Post mode: context. request.form["Textname"]
Get mode receive: String name = Context. request.querystring["Name"]
1.2 via Hyperlink <a href= ' simplelogin.ashx?name=hello ' >test URL get</a>
Request: There is a QueryString Form params property params is a collection of data submitted by the customer (can be used for post and get)
Three, the principle of redirection
Context. Response.Redirect ("hello.html");
Response: Write (output) redirect (redirect) end (end output)
Four, display the data to the template page
Get to template content
String Modelpath = context. Server.MapPath ("loginmodel.html");
String htmlsendback = System.IO.File.ReadAllText (Modelpath);
Replace the identification number in the content with the corresponding data variable
Five, write a login module with general procedure
Simplelogin.ashx
============================ Code =========
public void ProcessRequest (HttpContext context) {
Find the corresponding page
String Modelpath = context. Server.MapPath ("loginmodel.html");
Read the contents of the page
String htmlsendback = System.IO.File.ReadAllText (Modelpath);
Represents the output HTML
Context. Response.ContentType = "text/html";
Passing data to a template page
String num = "Linzhouzhi";
Htmlsendback = Htmlsendback.replace ("{num}", num);
Output to Browser
Context. Response.Write (Htmlsendback);
Hyperlink value-Passing method
Context. Response.Write ("<a href= ' simplelogin.ashx?name=hello ' >test url get</a>");
Get mode to receive data
String name = Context. request.querystring["Name"];
Context. Response.Write (name);
if (!string. IsNullOrEmpty (context. request.form["Textname"]) {
if (context. request.form["Textname"] = = "Linzhouzhi" && context. request.form["textpwd"] = = "111")
{
Context. Response.Write ("okokok!!");
End output
Context. Response.End ();
Context. Response.Write ("Helloword");
}
else {
redirect
Context. Response.Redirect ("hello.html");
}
}
}
=============loginmodel.html================
<body>
<form action= "Simplelogin.ashx" method= "POST" >
<input type= "text" name= "Textname" value= "{num}"/>
<input type= "text" name= "Textpwd"/>
<input type= "Submit" value= "Login"/>
</form>
</body>
ASP. NET generic Handlers