General processing procedures
Suffix:
Front page:. ashx
Background page:. Ashx.cs
Open With: Right-click the assembly--View in browser--Enter a URL (such as HTTP://LOCALHOST:6560/FIRSTASHX.ASHX) Firstashx.ashx is the name of the generic handler
ASHX processing mechanism (flow):
The browser sends the request to the server Iis,iis receive the request to the processing mapping pool to find the corresponding class file to Aspnet.isapid (intermediate handler) The intermediate handler then gives the class file to the Asp.fromwork framework, then finds the foreground page class according to the ASHX, then finds the background page class according to the instruction set of the foreground page class, and finally calls the ProcessRequest method of the Background page class, executes the inside code and returns to the server.
Instruction set: There is no practical meaning to our programmer, and when the compiler sees our set of instructions, it will find our corresponding backend code according to Codebehind.
<%@ WebHandler language= "C #" codebehind= "FirstAshx.ashx.cs" class= "generic handler. Firstashx"%>
The background page of the general handler implements the IHttpHandler interface
The code "text/html" of the output image in the PR method in the generic handler
Context. Response.ContentType = "text/html"; The output is HTML code can also directly do not the default is also output HTML code//output text is Text/plain
Context. Response.Write ("
To display the data in the browser: context. Response.Write ("Input to display the East is OK");
Get and Post pass values
Four ways to get a value: Get submitted data is displayed in URL unsafe
1.url value, manually modify the URL: In the path (question mark)? Separating parameters from Parameters & Connection
2. Use hyperlinks such as:
<a href= "Getdata.ashx? Id=2&name= Xiao Ming "> Super Connect Value </a>
3. Pass the value by JS method
<input Type=button onclick= "Go ()" value= "JS Pass Value" >
<script type= "Text/javascript" >
function Go () {
Window.location= "Getdata.ashx? Id=2&name= Xiao Ming ";
}
</script>
4.form table only son value (this is important)
<form action= "Getdata.ashx" metthod= "Get" >
<intput type= "text" name= "id" value= "2" >
<intput type= "text" name= "name" value= "Xiao Ming" >
<input type= "Submit" value= "<form>" >
</form>
Attention:
1. Submit the data must be in form form
2. The value of the tag must have the name attribute
A Submit button or Submit method must be in the 3.Form form
Post value: URL does not display transmitted data, more secure
There is only one way form forms
Similar to the previous form form, which is to change the method= "POST" value to post
Context. Request.handler can fetch the contents of the message header
Get the current request way request way default is uppercase
String Method=context.reqiest.httpmethod;
String Id=context. requesst.querystring["id"];//Gets the value passed in can only receive the value sent by the GET request.
String Id=context. requesst.querystring["Name"];
Gets the value of the post pass value to use the form property
String Method=context.reqiest.httpmethod;
String Id=context. requesst.form["id"];
String Method=context.reqiest.httpmethod;
String Id=context. requesst.form["Name"];
You can also use the context. requesst["id"]; receiving get and post values does not require the QueryString and form attributes used above but performance is not that high
Find the path to the template page
String Path=context. Server.MapPath ("/get/templ.html");
Read the contents of the template
String Str=system. Io. File.readalltext (path);
Build connection string
System.text.StringBuilder sb=new System.Text.StringBuilder (200);
Replace the placeholder Futi in the template page
Str=str. Replace ("$ (TRS)"). Sb. ToString ());
Output Content Response
Context. Response.Write (str);
Redirect: Redirect to another page
The server sends commands to let the browser jump
Redirect () This method will do three things:
1. Call the Clear method to empty the data inside the Response.Write ()
2. Modify the status code to 302 and set location
3. Call the end method to close the request
Web-----"" General processing program ASHX