Asp. The technique of URL mapping in net

Source: Internet
Author: User
Tags comments new features stack trace

The following mappings are often used in projects

Will
Http://yyjcw.com/a.aspx?name=llinzzi
Mapped to
Http://yyjcw.com/llinzzi
There are 2 problems to solve first
The first is to support wildcard mapping URL mapping is asp.net2.0 new features, do not support wildcards
Then the Nbear NBear.Web.Modules.UrlRewriteRules is used to map wildcard characters.


<?xml version= "1.0"?>
<!--
Note: In addition to manually editing this file, you can also use the
WEB Administration Tool to configure settings for your application. Can be used in Visual Studio
The Web site-> the asp.net configuration option.
The complete list of settings and comments is
Machine.config.comments, this file is typically located in the
In WindowsMicrosoft.NetFrameworkv2.xConfig
-->
<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= "/>
           <add type= "NBear.Web.Modules.UrlRewriteModule, Nbear.web" name= "Urlrewritemodule"/>
        
    <!-- 
            Set compilation debug= "True" to insert debug symbols into
             a compiled page. However, this value is   only during development because it &NBSP
            affects performance;
            set to True.
       
        < Compilation debug= "true" defaultlanguage= "C #"/>
        <!--
            PassThe;authentication> section can configure the   used by asp.net;
            Secure authentication mode,
            to identify incoming users. &NBSP
       
        < Authentication mode= "Windows"/>
        <!--
             If an unhandled error occurs during the execution of the request, the
             the corresponding processing steps can be configured through the <customErrors> section. Specifically,
            developers can configure
    through this section          HTML error page to display
             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>

Test success in VS2005, but failed to put in IIS

Checked a few times, did not find the problem, think carefully

First, the workflow for IIS should be to encounter an. aspx extension and give it to. NET processing before calling httpmodules for URL mapping
Http://yyjcw.com/llinzzi
No aspx extension, so IIS is directly a file rack, returning 404 errors
The debug Web server in vs2005, however, succeeded by sending all requests to. NET processing.
So change the image
<rule key= "/(. *)/index.aspx" value= "/a.aspx?name=$1"/>
Browse
Http://yyjcw.com/llinzzi/index.aspx
The test was successful.
Happy, set the index.aspx as the default document
Test http://yyjcw.com/llinzzi/; The result is still 404 error
Think about it. IIS believes that the Llinzzi folder does not exist and naturally does not use the default document to access

Depressed, thinking a lot of ways, all failed
Do you want to use llinzzi/index.html access? Do you want to generate a folder that really exists?
are not the ideal solution.

While attempting to modify the ISAPI from the configuration in the home directory in IIS to implement the parsing of the folder against IIS, I suddenly discovered that the IIS6 on the WINDOWS2003 server compared to the IIS5 on my work machine XP, called
Wildcard application mapping settings, eye light. The first name sounds like a door, and the No. 22003 is built for. Net. So dot Insert,
Input C:windowsmicrosoft.netframeworkv2.0.50727aspnet_isapi.dll
Test, Success!

Searched for the following information about wildcard application mappings

Install wildcard Application Mappings
In IIS 6.0, an administrator can configure a Web site or virtual directory to run an Internet server API (ISAPI) whenever a request is sent to a Web site or virtual directory, regardless of the file name extension requested.

When an IIS Web server receives a request from a client, the Web server looks at the file name extension that is named in the request to determine which ISAPI or public gateway Interface (CGI) application is to process the file. For example, if you request a Web page named Default.asp, IIS can know from the list of application mappings that Default.asp is handled by the Asp.dll ISAPI application.

If you want to perform a specific task on each client request before the requested page is sent to the mapped application, you can write an ISAPI filter to intercept the request when it arrives. However, the ISAPI filter has the following limitations:

They do not have access to the request body, but only to the headers.
They can only be configured at each site, not in 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 less functionality than the ISAPI extension API, which is used to write ISAPI applications.
They are difficult to manage in time.
They are event-driven.

By using the wildcard application mappings, you can intercept each request before the requested page is sent to its mapped application. The effect is like having an application map that handles each file name extension. This is why you use the wildcard character to name this feature. Applications that use wildcard application mappings can only be ISAPI applications.

Client requests take the following route:

Incoming requests are processed by any existing ISAPI filters that are installed on the root Web site. The ISAPI filter executes sequentially. &NBSP
requests are sent to any existing wildcard application-mapped applications, which are executed sequentially. If the incoming request is for a Web file in the virtual directory, and the wildcard application mapping is already installed on the virtual directory and the root Web, only the wildcard application mappings installed in the virtual directory are executed. If no wildcard application mappings are installed on the virtual directory, the wildcard application mappings that are installed on the Web site are executed. In other words, the wildcard application mappings are inherited only if there is no mapping in the application where the requested Web file is in. &NBSP
The IIS server looks at the application mapping table to determine which ISAPI application or CGI script specifically handles the requested file. &NBSP
Each stage can attach a response and then pass back to the client. &NBSP
Use wildcard application Mappings
Wildcard application mappings can be used in the following scenarios:

High-security WEB applications, such as banking applications, require that each requesting user be authenticated based on the user name, password, and account number database. For example, once a user has passed authentication, a specific rule is created that will specify what information the user can access. If the wildcard application mapping determines that the user does not have the appropriate rights, it can block further access to the request, or send the request to a Web page other than the requested page. This custom authentication and authorization scheme can be executed in an ISAPI application and installed as a wildcard application mapping. In this way, all users must authenticate, regardless of the file name extension that they requested.
Ad-commerce sites for individual users. For example, when a user's request is returned, the wildcard application mapping application checks their identities and then queries the items they have previously viewed or purchased. Once the wildcard script map transfers control to the requested page, it can display ads that are appropriate for that user.
Important You must be a member of the Administrators group on the local computer or you must be delegated the appropriate permissions to perform the following steps. As a security best practice, log on to the computer using an account that is not part of the Administrators group, and then run IIS Manager as an administrator using the Run as command. At the command prompt, type runas/user:administrative_accountname mmc%systemroot%system32inetsrviis.msc.

To add a wildcard application mapping to a Web server or Web site

In IIS Manager, expand the local computer, expand the Web Sites folder, right-click the Web site or virtual directory that you want, and then click Properties.
Click the appropriate tab: Home directory, virtual directory, or directory.
In the Application Settings area, click Configure, and then click the Mappings tab.
To install the wildcard application mappings, do the following:
On the Mappings tab, click Insert.
Type the path to the DLL in the executable text box or click Browse to locate the file, if the DLL file is a script engine, select the Application engine check box, and then click OK.
To edit or delete a wildcard application mapping, do the following:
In the Application Extensions list, click the script map that you want to change.
Click Edit to change the script map, or click Delete to delete the script map.
To change the order in which the wildcard application is executed, rearrange the wildcard application mappings in the wildcard Application mappings (execution Order) box by clicking the Move up or Move Down button until the order you want is met.
Note Do not list the same application multiple times in the wildcard Application Mappings list.

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.