What is the difference between files suffixed with axd and ashx?

Source: Internet
Author: User

In fact, the extension ashx is basically the same as axd. It is used to write web handler and can be used to call the IHttpHandler class. the control parsing and page processing process of the aspx page.
The only difference is that the axd extension must be registered in Therefore, in the Add file of the project, the wizard only adds the template of the ashx file, but does not add the template of the axd file. Why is it that Microsoft is so bored with two suffixes that it is not enough to use all of ashx? Neat and neat. It turns out that if your web handler code is not in the Web project, you cannot use ashx because it is not in the web project. if it is registered in config, the system does not know which dll library to find the corresponding code.
For example:
<Add verb = "*" path = "OpenSearch. axd "type =" Company. components. httpHandler. openSearchHandler, (namespace. class Name) Company. extensions (. dll file name) "validate =" false "/>
Only after registration, the web will know that OpenSearch. axd was originally in Company. Extensions. dll and processed using the Company. Components. HttpHandler. OpenSearchHandler class.
Of course, you just need to set up <add verb = "*" path = "OpenSearch. ashx" type =... that's not a problem, so it's just a habit.
In webconfig, the write principle is that iis will first handle the. axd file, and then hand it to FreeTextBoxControls. AssemblyResourceHandler, the class named FreeTextBox for processing instead of letting aspnet process it.

However, your server provider may remove the asping from. axd to aspnet_isapi.dll for security reasons, so you will be wrong when running on the server. The only thing you can do now is to contact your server provider to restore the ing.
 
Extension:. axd
Execution file: C: \ WINDOWS \ Microsoft. NET \ Framework \ v1.1.4322 \ aspnet_isapi.dll

Restrictions: GET, HEAD, POST, DEBUG
Script Engine check

There is a default ing in IIS on the server: ing *. axd to aspnet_isapi.dll.

 

 

Use WebResource provided by ASP. NET 2.0 to manage resources
ASP. NET (1.0/1.1) provides us with a WebControl programming model, so we get rid of the reuse of the include Mode in asp. However, the Web control development model provided by 1.0/1.1 is quite handy for components that do not have external resources such as image and css. Although scripts are often external resources, however, when developing controls, we are used to using pages for scripts. register... script () is used to embed modules. Because compact things are easier for us to reuse, a dll can solve the problem.

The Web Resources management model provided by ASP. NET 2.0 can effectively manage external Resources such as image, css, and script. Now you only need to set the build action attribute of the Resource file to Embedded Resource in solution explorer. Then add the following sentence to assemblyinfo. cs:
[Assembly: WebResource ("WebCtrl.cutecat.jpg", "image/jpg")] We can see that there is a WebResource parameter description in msdn: the first is the resource name, the second is the mime-type name of the resource.
In fact, this statement is stored in any cs file to ensure that it is placed outside the highest level of namespace.

Then, call the following in the program:
M_Image.ImageUrl = this. page. getWebResourceUrl (typeof (WebCustom), "WebCtrl.cutecat.jpg"); the first parameter of GetWebResourceUrl is the user-defined type (which is used to determine the assembly), and the second parameter is the resource name.

The Code returned by the preceding statement to browser is:
src is returned after GetWebesourceUrl is executed, it has three parameters (& resolved to & amp; here, but also recognized by IIS). The first parameter a is through typeof (WebCustom) the name of the assembly, the second parameter r is obviously the name of the resource, and the third parameter t is the timestamp of the assembly referred to by. This t is used to optimize browser cache for resource reference, because IE has its own cache mechanism for the same url. This r is also the timestamp of the user assembly file. If the user updates the code, t will change after re-compilation, which ensures that the browser can obtain the latest resource update. If we can determine that the embedded resources do not need to be updated, we can write a type in bcl in typeof (), such as typeof (string ), then, the t will be changed only after the freamwork upgrade.

Of course, this WebResource. axd does not exist. It is only an ISAPI in IIS.

The sample code is as follows:
[Csharp]
# Region WebResource Demo

Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Text;
Using System. Web. UI;
Using System. Web. UI. WebControls;

[Assembly: WebResource ("WebCtrl.cutecat.jpg", "image/jpg")]

Namespace WebCtrl
{
[DefaultProperty ("Text")]
[ToolboxData ("<{0}: WebCustom runat = server> </{0}: WebCustom>")]
Public class WebCustom: WebControl
{
Private string text;
Private Image m_Image;

[Bindable (true)]
[Category ("Appearance")]
[DefaultValue ("")]
Public string Text
{
Get {return text ;}
Set {text = value ;}
}

Protected override void CreateChildControls ()
{
M_Image = new Image ();
This. Controls. Add (m_Image );
}

Protected override void Render (HtmlTextWriter output)
{
M_Image.ImageUrl = this. Page. GetWebResourceUrl (typeof (WebCustom), "WebCtrl.cutecat.jpg ");
This. RenderChildren (output );
}
}
}
# Endregion

# Region WebResource Demo
 
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Text;
Using System. Web. UI;
Using System. Web. UI. WebControls;
 
[Assembly: WebResource ("WebCtrl.cutecat.jpg", "image/jpg")]
 
Namespace WebCtrl
{
[DefaultProperty ("Text")]
[ToolboxData ("<{0}: WebCustom runat = server> </{0}: WebCustom>")]
Public class WebCustom: WebControl
{
Private string text;
Private Image m_Image;
 
[Bindable (true)]
[Category ("Appearance")]
[DefaultValue ("")]
Public string Text
{
Get {return text ;}
Set {text = value ;}
}
 
Protected override void CreateChildControls ()
{
M_Image = new Image ();
This. Controls. Add (m_Image );
}
 
Protected override void Render (HtmlTextWriter output)
{
M_Image.ImageUrl = this. Page. GetWebResourceUrl (typeof (WebCustom), "WebCtrl.cutecat.jpg ");
This. RenderChildren (output );
}
}
}
# Endregion

 

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.