ASP. net mvc applications use axd format files

Source: Internet
Author: User

Axd format files, whether in asp.net or now developing asp.net MVC applications, are preferred by Insus. NET.

Because we can Virtualize a file that does not exist in the application. In fact, the file in this format is Handler, which implements the IHttpHandler interface. Therefore, you can create an axd to replace the ashx file.

The following example shows how to create, configure, and apply an ASP. net mvc application in Insus. NET.


In the Handlers directory, create a cs class named Axd. cs. This class name only complies with the naming rules of the C # class.

 
The main point of this class is to implement the IHttpHandler interface.
The Axd is created, but it cannot be used directly. It also needs to be configured in Web. config:

 

Under the handlers subnode under the System. webServer node,

Add:

 


Mark 1 to specify a name.

Mark 2. This is the key point. The external name is a file name that can be seen during user access. But you can define it as the same as the class name you created above. However, Insus. NET is used to use a name different from the class name.
Mark 3, which is the full name of the class, including the namespace.


At this point, we can test it, but before testing, we also need to check your route Configuration:




In the address bar of the browser, enter http: // localhost: 50369/I. axd? V = leo. Pay attention to the highlighted syntax.


For more in-depth demonstration, create an operation on the MVC controller:

 

Create a view:

 

Real-time operation Demonstration:

 

 

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.