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:)