Recently, in the internal system of our unit, use the functionality of the THEME (topic) in ASP.NET 2.0. The core of this feature is a dynamic CSS definition that sends different CSS style text according to different subject content selected by the user.
This problem is very good, use one in the
area in HTML:<% # = Base.getcssinclude ()%>
You can solve it, but I have no use.
I pay attention to the Generic Handler item in the web application project template in VS2005, found that it is a .ashx file, actually it is an httphandler. Later, I checked the .NET SDK document, found that ASP.NET1.1 also supported .ashx, but did not give details.
We all know that httphandler is a way to completely customize the HTTP request. It is used to filter out the HTTP request to be customized by web.config, and send it to the specified class defined in Web.config.
Using the .ashx file is a better way, this file is similar to the .aspx file, you can call the HTTPHANDLER class through it, eliminating the control parsing of the normal .aspx page, and the process of page processing. This file is particularly suitable for generating dynamic pictures, generating dynamic texts.
The establishment method is as follows:
First open a web project, then use the VS2003 Solution Explorer "Add" -> Add New Item in any directory, select Text Files in the dialog box, and enter "TextBuilder at the file name. ASHX ".
Then enter "TextBuilder.ASHX.CS" in the class file name using the Solution Explorer, using the Solution Explorer. It can be seen that its file naming rules are the same as the .aspx file.
Then enter the following code at the .cs file (name space):
Using
System.Web
public
SeaD
Class
TextBuilder: IHTTPHANDALER
{Public void ProcessRequest (HttpContext context) {context.Response.ClearContent (); context.Response.ContentType = "text / plain"; context.Response.Write ( "Hello World"); context.Response.End ();} Public Bool Isreusable {get {return true;}}}
Then enter the call code for the above class at the first row of the "TextBuilder.ashx" file:
<%
@ WebHandler language = "c #" class = "mynamespace.textbuilder" codebehind = "textbuilder.ashx.cs"
%>
The above code needs to be aware that the full name of the class must be entered in the Class item, that is, the namespace and class name.
Finally, save and compile the project.
Use the IE test to enter this .ashx address.
You can see that the Response class has an OutputStream method, you can output binary data streams to the client, so use this method in my project, in one .ashx, use the dundaschart control to generate a very good chart, with it Send binary data, convenient and fast, and do not need to enter any configuration code in Web.config. The .ashx file has a disadvantage, he handles the reputation of the control. For example, if you use it to generate a list of DataGrid, it is not not possible, but the process of processing the data, it requires some .aspx page, only manual processing these functions. So, usually use .ashx, used to output some items that do not need to return process.
Reference: http://www.cnblogs.com/submaie/archive/2005/01/22/95778.html