The context in the C # Development Web program about generic handlers. Response.ContentType = "Text/plain"

Source: Internet
Author: User

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/plain

Concepts 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"

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.