ASP. net2.0 URL ing implementation skills

Source: Internet
Author: User
In a project, you often need to map the following to http://onewww.net/a.aspx? Name = llinzzi
Map to http://onewww.net/llinzzi
First, we need to solve two problems.

The first is to support wildcard ing.

URL ing is a new feature in ASP. net2.0 and does not support wildcards.

The nbear. Web. modules. urlrewriterules
Wildcard ing

<? XML version = "1.0"?>
<! --
Note:
In addition to manually editing this file, you can also use
Web management tools to configure application settings. You can use Visual Studio
In
"Website"-> "ASP. NET configuration" option.
The complete list of settings and comments is displayed in
Machine. config. Comments
The file is usually located in
\ Windows \ Microsoft. NET \ framework \ v2.x \ config
Medium
-->
<Configuration
Xmlns = "http://schemas.microsoft.com/.NetConfiguration/v2.0">
<Configsections>
<Section
Name = "urlrewriterules" type = "nbear. Web. modules. urlrewriterules,
Nbear. Web "/>
</Configsections>
<Urlrewriterules>
<Rule
Key = "/(. *)/" value = "/a. aspx? Name = $1 "/>
<Rule key = "/(.*)"
Value = "/a. aspx? Name = $1 "/>
</Urlrewriterules>

<Appsettings/>

<System. Web>

<Sessionstate
Timeout = "200"/>
<Httpmodules>
<Add
Type = "nbear. Web. modules. urlrewritemodule, nbear. Web"
Name = "urlrewritemodule"/>
</Httpmodules>

<! --
Set
Compilation DEBUG = "true" insert the debugging symbol
Compiled pages. However, this
Performance is affected, so this value is only available during development.
Set
True.
-->
<Compilation DEBUG = "true" defaultlanguage = "C #"
/>
<! --
In the <authentication> section, you can configure

Security Authentication mode,
To identify the user.
-->
<Authentication
Mode = "Windows"/>
<! --
If an unprocessed error occurs during request execution,
Then pass
In the <customerrors> section, you can configure the corresponding processing steps. Specifically,
This section allows developers to configure
Html
Error Page
To replace the error stack trace.

<Customerrors mode = "remoteonly"
Defaultredirect = "genericerrorpage.htm">
<Error statuscode = "403"
Redirect = "noaccess.htm"/>
<Error statuscode = "404"
Redirect = "filenotfound.htm"
/>
</Customerrors>
-->
</System. Web>
</Configuration>

The test is successful in vs2005, but it fails to be put in IIS.

I checked several times and did not find any problems. I thought about it carefully.

First, the IIS workflow should meet the. aspx extension and be handed over to. Net for processing before you can call httpmodules for URL ing.
Http://onewww.net/llinzzi
No aspx extension, so IIS is used as a file shelf and Error 404 is returned.
The debug web server in vs2005 sent all requests to. Net for processing, so the request was successful.
Therefore, it is changed
<Rule
Key = "/(. *)/index. aspx" value = "/a. aspx? Name = $1"
/>
Browse
Http://onewww.net/llinzzi/index.aspx
The test is successful.
Happy! Set index. aspx to the default document
Test whether the result of http://onewww.net/llinzzi /#Error 404
I thought about IIS and thought that the llinzzi Folder does not exist. Naturally, it is useless to access the default document.

Depressed, failed after thinking a lot of methods
Do you want to use
Llinzzi/index.html access? Do you want to generate a folder that actually exists?
None of them are ideal solutions

When you try to modify the ISAPI from the configuration in the main directory of IIS to parse IIS using folders, I suddenly found that IIS6 on Windows Server has an additional setting named wildcard application ing than iis5 on Windows XP .. it sounds like the first word, and the second 2003 is.. net. click Insert,
Input
C: \ windows \ microsoft.net \ framework \ v2.0.50727 \ aspnet_isapi.dll

Test, successful!

Searched for information about the wildcard application ing.

Install wildcard application ing
In IIS 6.0
The administrator can configure the website or virtual directory to run the Internet Server API
(ISAPI) regardless of the file extension.

When the IIS web server receives a request from a client
The server will view the file extension named in the request to determine which ISAPI or public Gateway Interface (CGI) application is available to process the file. For example, if the request name is default. asp
IIS can know from the application ing list that default. asp is created by ASP. dll ISAPI
Application processing.

If you want to execute a specific task for each client request before the requested page is sent to the mapped application, you can write an ISAPI
The filter intercepts the request when it arrives. However, the ISAPI filter has the following restrictions:

They cannot access the Request body, but only the access header.

They can only be configured on each site, but not on each virtual directory.
They should not contain long-running operations because ISAPI filters are synchronized.

They are less flexible because the ISAPI filter API has fewer functions than the ISAPI extension API, which is used to compile ISAPI applications.

They are difficult to manage in time.
They are event-driven.

By using wildcard application ing, You can intercept each request before the requested page is sent to its ing application. The effect is like an application ing that processes each file name extension. This is why "wildcard" is used to name this function. Only
ISAPI application.

Client requests use the following routes:

The incoming request is processed by any existing ISAPI filter installed on the Root website. ISAPI
Filters are executed in sequence.
Requests are sent to any existing wildcard application mapped applications, which are also executed in sequence. If the incoming request is for the Web
File, and the wildcard application ing has been installed in the virtual directory and the root site, then only the wildcard application ing installed in the virtual directory will be executed. If no wildcard application ing is installed on the virtual directory, the wildcard application ing installed on the website is executed. In other words, the wildcard application is mapped only to the requested
The application where the Web file is located does not have a ing.
The IIS server will view the application ing table to determine which ISAPI application or CGI
The script specifically processes the requested file.
Each stage can append a response and send it back to the client.

Use wildcard application ing
Wildcard application ing can be used in the following scenarios:

High Security Web
Applications (such as banking applications) require Identity Verification Based on the username, password, and account number database of each user making a request. For example, once a user passes authentication, a specific rule is created that specifies the information that the user can access. If the wildcard application ing determines that the user does not have the corresponding rights, it can block further access to the request, or send the request to a webpage other than the requested webpage. This custom authentication and authorization solution can be found in
Run in the ISAPI application and install it as a wildcard application ing. In this way, all users must pass authentication, regardless of the file extension they requested.

An advertisement e-commerce website targeting a single user. For example, when a user's request is returned, the wildcard application ing application checks their identity and then queries the items they previously viewed or purchased. Once the wildcard script ing is transferred to the requested page, the ads that are suitable for this user can be displayed.

Important you must be a member of the Administrators group on the local computer or be granted permissions to perform the following steps. As the best security operation, please use does not belong
The account in the Administrators group logs on to the computer, and then runs the IIS manager as an administrator by running commands. At the command prompt, type RunAs
/User: administrative_accountname "MMC
% SystemRoot % \ system32 \ inetsrv \ IIS. msc ".

Add a wildcard application ing to a Web server or website

In
In IIS manager, expand the Local Computer, expand the "website" folder, right-click the desired website or virtual directory, and then click "properties ".

Click the corresponding tab: "main directory", "virtual directory", or "directory ".
In the application settings area, click configuration, and then click the ing tab.

To install the wildcard application ing, perform the following operations:
On the ing tab, click Insert ".
In the executable file text box, type DLL
Or Click Browse to find the file. If the DLL file is a script engine, select the application engine check box and click OK ".

To edit or delete the wildcard application ing, perform the following operations:
In the Application Extensions list, click the script ing you want to change.

Click Edit to change the script ing, or click Delete to delete the script ing.

To change the execution sequence of a wildcard application, reschedule the wildcard application ing in the "wildcard application ing (execution sequence)" box, you can click the "Move Up" or "Move Down" button until it meets the order you want.

Note: do not list the same application multiple times in the wildcard application ing list.

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.