ASP. NET pure code implements pseudo static address (URL rewriting)

Source: Internet
Author: User
I am a beginner. I dare not talk about the specific implementation principle. I just wrote the usage method for your reference. (In this example, I used the HTTP module to rewrite the URL)
1. Rewrite showplay1.aspx to showplay. aspx? Vid = 1:
1 download the DLL and put it under the bin directory of the website and directory:
Http://www.ckcom.cn/urlrewriter.rar

2. Add the following nodes in <system. Web> and </system. Web> of Web. config:

<Httpmodules>
<Add type = "urlrewriter. modulerewriter, urlrewriter" name = "modulerewriter"/>
</Httpmodules>

3. Add the following nodes in <configuration> and </configuration> of Web. config:

<Configsections>
<Section name = "rewriterconfig" type = "urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter"/>
</Configsections>

<Rewriterconfig>
<Rules>
<! -- Rewrite Rules -->
<Rewriterrule>
<! -- URL format to be implemented -->
<Lookfor> ~ /Showplay-(\ D {1, 4}) \. aspx </lookfor>
<! -- Real URL address. $1. $2, $3... $ n indicates the nth expression of Regular Expression matching. -->
<Sendto> ~ /Showplay. aspx? Vid = $1 </sendto>
</Rewriterrule>
</Rules>
</Rewriterconfig>

4. Adding a connection like a ShowPlay-1.aspx in the web page will be overwritten to showplay. asp? Vid = 1

2. Implement http://www.ckcom.cn/showplay1/rewrite to http://www.ckcom.cn/showplay.aspx? Vid = 1

The method is the same as step 1. Additionally, you need to ensure that default. aspx is added to the default Main Document of the website. The showplay1 directory must exist in the website directory and the default. aspx directory must exist in the showplay1 directory.
The corresponding rewrite rule should be changed

<! -- URL format to be implemented -->
<Lookfor> ~ /Showplay-(\ D {1, 4})/Default \. aspx </lookfor>
<! -- Real URL address. $1. $2, $3... $ n indicates the nth expression of Regular Expression matching. -->
<Sendto> ~ /Showplay. aspx? Vid = $1 </sendto>

Note the following when using this method:
1. You cannot use Windows to authenticate user permissions. Use Form for authentication. In web. config, configure it as: <Authentication mode = "forms"/>
2. The path obtained using request. servervariables ["script_name"] is still: showplay. asp? Vid = 1
3. If the address to be rewritten is sent back, the address to be overwritten will be showplay. asp? Vid = 1
4. The suffix name must be. aspx. If it is another custom suffix name, for example,. net, map. Net to aspnet_isapi.dll in IIS so that. Net requests can
To the Asp.net engine.

The level is limited until now. For detailed principles and solutions, see:
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx? PF = true

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.