Asp. NET Learning Notes 004--development of asp.net based on ashx mode 1
Source: Internet
Author: User
Previously written courses are not attached to the source code, I am sorry!
In the course of the source code can add QQ request: 1606841559
Technical Exchange QQ1 Group: 251572072
Technical Exchange QQ2 Group: 170933152
You can also download it yourself:
ASP. NET Learning notes 004 asp.net development based on HX approach 1.zip Http://credream.7958.com/down_20144363.html
Use examples to illustrate
Ashx and ASPX are two ways to handle foreground submission data:
Ashx
New/website1
Hello1.htm
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form action= "Hello1.ashx" >
Name: <input type= "text" value= "UserName" name= "UserName"/>
<input type= "Submit" value= "submitted"/>
<!--
The server only has the name attribute, and if the Name property repeats, it will only submit the first
ID is used for DOM
-->
</form>
</body>
---------------------------------------------------------------------------
Hello1.ashx
<%@ WebHandler language= "C #" class= "Hello1"%>
Using System;
Using System.Web;
public class Hello1:ihttphandler {
public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "Text/plain";//The Returned data is in TXT format
Writing plain here may result in the browser being recognized as XML
Context. Response.ContentType = "text/html";//indicates that the returned data is HTML
Write the original HTML to the browser:
String username = context. request["UserName"];//gets the HTML end, and returns the value of name UserName
Context. Response.Write (@ "<form action= ' hello1.ashx ' >
Name: <input type= ' text ' value= ' "+username+@" ' name= ' username '/>
<input type= ' Submit ' value= ' submitted '/>
</form> ");//write the original data into the control
Adding a @ In C # means multiple lines of text
Context. Response.Write ("Hello World");
Context. Response.Write (username);//write back to Browser
}
public bool IsReusable {
get {
return false;
}
}
}
---------------------------------------------------------------------------
Hello2.htm
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form action= "Hello2.ashx" >
Name: <input type= "text" value= "UserName" name= "UserName"/>
<input type= "Submit" value= "submitted"/>
<!--
The server only has the name attribute, and if the Name property repeats, it will only submit the first
ID is used for DOM
-->
</form>
</body>
---------------------------------------------------------------------------
Hello2.ashx
<%@ WebHandler language= "C #" class= "Hello2"%>
Using System;
Using System.Web;
public class Hello2:ihttphandler {
public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "text/html";
String FullPath = context. Server.MapPath ("hello2.htm");
String content = System.IO.File.ReadAllText (FullPath);
Direct access to this file will also be invoked
Context. Response.Write (content);
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