Simple static page calculator.html:
<! DOCTYPE html>
Plus General Handler Calculatorhandler.ashx:Using system;using system.collections.generic;using system.linq;using system.web;namespace WebDemo.Handlers{ /// <summary> /// calculaterhandler 's summary description /// </summary> public class CalculaterHandler : IHttpHandler { public void processrequest ( Httpcontext context) { //context. response.contenttype = "Text/plain"; context. response.contenttype = "Text/html"; string num1 = context. request.params["Number1"]; string Num2 = context. request.params["Number2"]; int Result = convert.toint32 (NUM1) + convert.toint32 (num2); //context. Response.Write (num1 + "+" +num2+ "=" +result); string html = @ "<! doctype html >
Note that these two sentences will result in different results: in context. Response.ContentType = "Text/plain"; The result is output text as-is. Use the context. Response.ContentType = "text/html"; the result is the normal HTML format output.
The difference between text/html & Text/plainConcepts to understand
Content-type: defines how the user's browser or related device Displays the data that will be loaded, or how to handle the data that will be loaded
MIME:MIME type is the type of file that is set up with an extension that is opened by an application, and when the extension file is accessed, the browser automatically opens with the specified application. Many are used to specify some client -defined file names , as well as some ways to open media files.
Text/html means that the content-type of the file is set to the form of text/html, and the browser automatically calls the HTML parser to process the file when it obtains the file.
Text/plain means that the file is formatted as plain text, and the browser does not process the file when it obtains it.
The context in the C # Development Web program about generic handlers. Response.ContentType = "Text/plain"