In. net, change aspx to another suffix

Source: Internet
Author: User

.

The legendary Method 1: (originated from http://topic.csdn.net/t/20050203/10/3772606.html)

Truly () on the 47 th Floor replied to the score of 15 at 20:19:58

1. IIS default site-home directory-settings-add-

Executable: C: \ WINDOWS \ Microsoft. NET \ framework \ v1.1.4322 \ aspnet_isapi.dll
Extension:. mspx

OK

2. Web. config
<System. Web>
<Httphandlers>
<Add verb = "*" Path = "*. mspx" type = "system. Web. UI. pagehandlerfactory"/>
</Httphandlers>

The legendary Method 2: httphandler httpmodule makes a webpage with its own suffix!

first, let's talk about some Asp.net parameter passing and page targeting methods
first, Asp.net uses page. navigate () to call the URL of a new page. Page. navigate () returns an HTTP status code 302 to the browser, allowing the browser to request the new URL to the server. This navigation method requires two rounds between the client and server for each customer request.
Second, any information to be transmitted to the new page must be used as URL parameters, stored in sessions, or stored in databases for the new page to obtain the information. Traditional ASP developers are used to this practice, but other web programmers have more advanced methods. However, the two pages are obviously dependent, and the dependency is not captured by the compiler and is not easily modeled at the design stage. Therefore, when debugging, whether the parameter is correctly passed is checked by ourselves. In addition, traditional data transmission methods may expose some key data. More importantly, this makes the object-oriented design very complex.

but we can customize httphandler to expand this support.
to study httpmodule and ihttphandler, you must first understand ASP. NET processing pipelines.
in ASP. in the Program Of the. NET application, the system uses a group of related classes to process client requests (requests) and ASP. NET application processing mode can be called HTTP processing pipeline.
httpmodule and ihttphandler are two processes in the processing pipeline. Classes in the HTTP processing pipeline are in the system. the following types are defined in the Web namespace: The httpworkerrequest abstract class defines ASP.
httprutime provides a set of services for processing applications.
httpcontext stores all the context information related to processing a request;
httpapplicationfactory provides applications for related directories.
httpapplication defines all ASP. NET applications. This class is also in the user's global. the base class of the application defined in the asax file;
modules handles pre-request and post-response events;
handlerfactories provides handlers in the application;
handlers processes requests and responses.

On Windows, HTTP pipline requires IIS support. To run ASP.. NET application. IIS requires the following two files: aspnet_isapi.dll and aspnet_wp.exe aspnet_isapi.dll are an ISAPI extention that will be sent to IIS. Please transfer aspnet_wp.exe to process aspnet_wp.exe and use httpruntime to process the request as follows:

The following is a simple example! 1) create a project named simplehandler and add a class myhandler. CS,CodeAs follows:

Namespace simplehandler
{
Public class myhandler: ihttphandler
{
Public void processrequest (httpcontext CTX)
{
Httpresponse response = CTX. response;

Response. Write ("My first handler! ");
}
Public bool isreusable
{
Get {return true ;}
}
}
}

2) Compile the above Code to generate the simplehandler. dll file;

3) create a new web project and add the simplehandler. dll file to the reference of the project;
4) modify web. config and add the following content:
<System. Web>
<Httphandlers>
<Add verb = "*" Path = "*. aspx" type = "simplehandler. myhandler, simplehandler"/>
</Httphandlers>
</System. Web>
Options in the configuration file:
Verb can be "get" or "Post", indicating that the get or POST request is processed.
"*" Indicates that all requests are processed.
Path indicates processing the corresponding file. "*. aspx" indicates processing the requests sent to all aspx pages. You can specify a path, such as "/test/*. aspx", indicating that the aspx file under the test directory is processed only.
In the type attribute, the string before the comma specifies the Class Name of the httphandler implementation class, and the subsequent string specifies the name of the DLL file.
Now, on any ASPX page in the request project, there is always only one line: My first handler!

Because our Custom Handler intercepts all requests sent to the ASPX page and uses its own method to process these requests.

To make our word definition page run smoothly, for example, *. AAA, we need to modify the Web. config file:
 
<System. Web>
<Httphandlers>
<Add verb = "*" Path = "*. AAA" type = "simplehandler. myhandler, simplehandler"/>
</Httphandlers>
</System. Web>
In order to make requests for files suffixed with. AAA be intercepted and run by our handler, we still need some additional work. Open the IIS console, click the site, and select "properties". The site Properties dialog box is displayed. Select the main directory option and select configuration. The application configuration dialog box is displayed ". AAA "added to application ing. now we can add. AAA file. When sending a request to this file, the browser displays: My first handler! Access to other aspx files is not affected.

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.