Development Distance: ashx file and aspx

Source: Internet
Author: User

What is the difference between a ashx file and an aspx file? Let's start with a new ashx file to see:

1 <%@ WebHandler Language="C #"Class="Handler" %>2 using System;3 using System.Web;4 Public class Handler:ihttphandler5 {6 Public void ProcessRequest (HttpContext context)7   {8 context. Response.ContentType = "Text/plain";9 context. Response.Write ("Hello World");Ten   } One Public bool IsReusable A   { - Get -      { the return false; -      } -   } -}

This is a new Handler. ashx file.

ASHX is a lot simpler than aspx. There is only one file, no background CS file (based on code security considerations, we will add this file ourselves). ashx Compare aspx files as if the CS file is missing. Actually, this is where ashx and aspx are different, Because ASPX separates the front and back display from the processing logic, it becomes two files, in fact, in the final compilation, the ASPX and CS will be compiled into the same class. This is about designing some logical processing of HTML. and ashx different, it's just simple on the web The HTTP request directly returns the result that you want to return. The process of processing HTML less than ASPX. Theoretically, faster than ASPX.

Take a look at the configuration of the two file type requests in the. NET config file:

1<add path="*.aspx"verb="*"Type="System.Web.UI.PageHandlerFactory"Validate="True"/>2<add path="*.ashx"verb="*"Type="System.Web.UI.SimpleHandlerFactory"Validate="True"/>

You can see that the class of two file processing is different (ASHX class called simplehandlefactory, since it is called simple, the process should be relatively simple.) should be quicker to respond:)

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.