Relationship between browser and IIS server and. Net FrameWork
Asp. Net
ASP. Net is a dynamic web page technology,Run. Net code on the server side, dynamically generate HTML, and then respond to the browser.
JavaScript and Dom can be used to do a lot of work on the browser side, but a lot of work cannot be done on the browser side, such as data storage, database access, complex business logic operations, and logic operations with high security requirements.
ASP. Net: general processing program (ashx), WebForm (aspx), MVC3 (Model, View, Controler ).
Common files in Asp. Net
File Extension |
Description |
. Ashx |
General processing program, ASP. NET core program, but general use. aspx [used when a large amount of html code is not returned] |
. Aspx |
Common Program: WebForm, which is used to create webpages and program webpages. Core File Types (front-end files) are used together with. aspx. cs files. [use it when a large amount of html code is returned] |
. Aspx. cs |
Common Programs are used to compile a large number of c # Business Code and use it with. aspx. |
. Ascx |
Specifies an ASP. NET user-defined Control |
. Asax |
Event syntax that contains ASP. NET application-level events |
. Config |
Configuration file, used to set various attributes of the website application |
. Asmx |
For local or remote use of the host Web Service |
HttpHandler)
Is a special class that implements the System. Web. IHttpHandler interface.
Any class that implements the IHttpHandler interface is a prerequisite for the target program of an external request. (Any class that does not implement this interface cannot be requested by the browser .)
It is called and started to run by servers that support ASP. NET. An HttpHandler program is responsible for processing the access requests of one or more of its corresponding URLs, receiving the access request information (Request Message) sent by the client and generating response content (Response Message ).
You can create an HttpHandler program to generate the browser code and send it back to the client browser.
The HttpHandler program can complete most of the tasks that can be completed by common class programs:
1. Obtain the data and URL parameters submitted by the client through the HTML Form
2. Create Response Message content for the client
3. access the file system on the server
4. Connect to the database and develop database-based applications
5. Call other classes
Simple use of ashx
Read model.html and return the processed html code to the browser.
Copy codeThe Code is as follows:
Using System. Web;
Namespace ASHX {
Public class Cul: IHttpHandler {// IHttpHandler very important interface implementation interface is to call the ProcessRequest processing PAGE method uniformly
// Note: Q2: why can the content be displayed by entering cul. ashx in the browser? A2: Because Cul. ashx is renamed during program compilation.
Public void ProcessRequest (HttpContext context) {// context request context object: all information requested by the browser is included in
Context. Response. ContentType = "text/plain"; // text/plain can be interpreted as a normal string. text/html can be interpreted as html.
// Note: if the text/plain content is output, a complete html page content will be automatically interpreted and executed by the browser because the browser is backward compatible.
// Obtain the physical path of the template page on the server
String PagePath = context. Server. MapPath ("Model.htm ");
// Read the template content
String HTMLStr = System. IO. File. ReadAllText (PagePath );
HTMLStr = HTMLStr. replace ("@ {title}", "This is the first static processing file "). replace ("@ {Content}", "I am using static processing to dynamically generate files ~ ~ ");
// Output to the page
Context. Response. Write (HTMLStr); // Response Server Response attribute
Context. Response. Write (""); // Q1: Why does "" and HTMLStr output together to the interface instead of overwriting?
// A1: Because Write actually writes data to the cache area of the HtmlWrite object in an HttpResponse object operated by the Response attribute.
// Q3: Why do I need to write data to the cache? A3: At this time, no response message is generated.
}
Public bool IsReusable {
Get {
Return false; // whether it can be reused
}
}
}
}
Html. modelThe Code is as follows:
Copy codeThe Code is as follows:
<Head>
<Title >@{ title} </title>
</Head>
<Body>
@ {Content}
</Body>
</Html>
Diagram of the code running principle