Step 1: Data System Technology (1. URL rewriting Technology Based on 404 errors)

Source: Internet
Author: User
The first article discusses the URL rewriting technology used in my website. In fact, this technology is not compiled by me. Some users may remember that my website www.step1.cn was originally a blog, at that time, the cnblogs provided by the blog Program (It took me a lot of time to modify this program to run on the current virtual host). After I migrated my blog here, I made a major revision of step1.cn, at that time, I was reluctant to use the URL rewriting technology in this blog program. Code Split it into a DLL class and use URL rewriting Technology on my website.
At that time, due to the excellent program structure of cnblogs.cn, I did not change much, mainly including the following:
1. URL rewriting Technology Based on 404 error. Some virtual hosts do not support URL rewriting. In particular, You need to rewrite the URL of static html files (of course, I didn't use this technology ), however, basically no VM supports URL rewriting of static html files (at least I have never used it), so I came up with a work und, that is, modify the settings on the server's 404 error page, direct the settings to a specific aspx file, and then call the cnblogs URL rewriting program in the aspx file.
The corresponding class code of error404.aspx: 1 Public   Class Error404: system. Web. UI. Page
2 {
3 Private   Void Page_load ( Object Sender, system. eventargs E)
4 {
5 If (Request. querystring ! = Null )
6 {
7 String [] Querystring = Request. rawurl. substring (request. rawurl. indexof ( " ? " ) + 1 ). Split ( New   Char [] {';'} );
8 If (Querystring. Length = 2   && Querystring [ 0 ] = " 404 " )
9 {
10 Uri URI = New Uri (querystring [ 1 ]);
11 String Query = Uri. query;
12 If (Query. startswith ( " ? " ))
13 Query = Query. substring ( 1 );
14 This . Context. rewritepath (URI. absolutepath, Uri. userinfo, query );
15 ( New Urlrewritehandlerfactory (). gethandler ( This . Context, request. requesttype, Uri. pathandquery, server. mappath (URI. localpath). processrequest ( This . Context );
16 This . Context. response. End ();
17 }
18 }
19 }
20 }

I have read the rest of the code. Most of the Code is from the source code of cnblogs, and the part I changed is very small. Therefore, I do not provide the source code in this article. If necessary, you can refer to the source code of cnblogs first You can send me an email to obtain the source code for this part. , Which can be provided directly.
In general, this URL rewriting mechanism adds a configuration similar to the following in the web. config file to implement the corresponding URL rewriting function: 1 < Httphandler Pattern = "^/Place/CN/([% 0-9a-za-z/] *). aspx $" Type = "Step1.urlrewriter. pagehandlerfactory, step1.urlrewriter" Handlertype = "Redirect" Pagelocation = "/Place. aspx? P = $1"   />
2

In the preceding configuration, the URL/place/CN/Aaaaaaa. Aspx automatically redirects to/place. aspx on the server side? P =Aaaaaaa
For details, I may refer to other technologies later.

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.