Profile
Analyze how to use the ASP.net provided by Microsoft to rewrite URLs that are dynamically generated URL addresses. URL rewriting is the process of implementing a request to intercept a Web site and then point it back to a specified URL. The author himself in the implementation of Web site rewriting technology research and explore the experience and methods, hope to be helpful to you.
Content Introduction
Take a little time to look at the URL in the website you're doing, do you see an address like this http://yoursite.com/info/dispEmployeeInfo.aspx? Empid=459-099&type=summary? Maybe you'll move a lot of paging files from one directory or even one site to another for some reason, many visitors have already collected the original URLs for personal interest or research purposes, and if he opens the page from the Favorites folder, he finds it is already a bad chain. The purpose of this article is to describe how to use URL rewriting to convert "unsightly" URLs to more meaningful URLs to make them easier to remember. For example will http://yoursite.com/info/dispEmployeeInfo.aspx? Empid=459-099&type=summary converted to the following address: http://yoursite.com/dispEmployeeInfo/459-099/summary.html. We have even found that URL rewriting technology can solve a 404 of headaches, or that it can create an intelligent 404 error solution.
As mentioned above, URL rewriting is the process of implementing a request to intercept a Web site and then point it back to a specified URL. During URL rewrite execution, the corresponding handler processes the requested URL, extracts the associated value, and then points back to a new specified address. For example: As a result of a site directory adjustment, all the pages in the original/people/subdirectory moved to the/info/employees/directory, the original visitors from the Favorites or other places click on the link to send access to the/people/directory of files under the request, You'd expect him to see the same page from the original address, but actually see the corresponding file in the new directory that the URL rewrite points to.
In the older version of ASP, there are few ways to use web site rewriting techniques, either by writing an ISAPI filter or by purchasing a URL rewrite component provided by a third-party vendor, but under the asp.net of Microsoft, you can easily develop your own URL rewriting software to meet your different needs in a variety of ways. This article will discuss with you the technology for implementing Web site rewriting for ASP.net developers, and then give some examples of URLs rewriting practical applications. Before we delve into the details of Web site rewriting techniques, let's take a look at the scenarios that are implemented using Web site rewriting techniques on a daily basis.
General purpose of Web site rewriting
The most common ASP.net program that creates a data operation is an ASPX page with a collection of query parameters behind it. For example, when designing an E-commerce site, assume that you have designed a feature that allows users to browse for items for sale, and for easier operation, You designed a page displaycategory.aspx the product according to the given classification display, then the product display page under the category should be in the page file corresponding to the URL after a product classification of the query parameters, such as users to inquire for the sale of "decorations", In the database, all the ornaments data corresponding to the category number CategoryID value of 5, then users will visit the following Web site: http://yoursite.com/displayCategory.aspx?CategoryID=5.
Create a Web site that contains a URL like this. Ultimately, there are two outcomes, first viewed from the end-user's perspective, http://yoursite.com/displayCategory.aspx? Categoryid=5 This web site is a bit messy, the feasibility analysis expert Jakob Neilson (home: http://useit.com/) recommend the choice of Web site display mode when consider the following requirements (reference URL: http://www.useit.com/ alertbox/990321.html):
• Is it short
• Easy to enter
• Whether the site structure is visualized
• Whether there is concealment, that is, let the user through a virtual seemingly meaningful navigation address access to the address
I think we should add one more to the list above: Is it easy to remember? Http://yoursite.com/displayCategory.aspx?CategoryID=5 This address does not have a place to meet any of the Neilson standards, nor is it easy to remember. Of course, for experienced network development experts, they are familiar with this key-value pairs of query parameter structure system, but for ordinary users to enter these parameters of the URL is too cumbersome.
A better approach is to use a more intuitive and easy to remember way to represent URLs as: http://yoursite.com/products/Widgets At first glance it is easy to infer that the content of this URL is likely to be display decorations (Widgets) information, this site becomes more easy to remember and spread! Then I told my colleague: "Please check this URL: http://yoursite.com/products/widgets" I don't need to say the second time, She might have knocked her address into the browser at once (you can also try this on Amazon's Amazon.com website). The contents of the decorations (Widgets) were soon listed on the browser. "Concealment" Here says: Users can change the end of their URLs, such as input: Http://yoursite.com/products can see all categories related to the list of items or list all the relevant categories of merchandise.
Note: Use the above simple way to change the content of the Web site to conceive of today's more popular blog web site generated. For example: To query the post posted January 28, 2004, simply enter HTTP://SOMEBLOG.COM/2004/01/28, if the site cut to HTTP://SOMEBLOG.COM/2004/01 will show the January 2004 post, The same month to cut off the http://someblog.com/2004 will show the year 2004 posted.
In addition to simplifying complex URLs, web site rewriting technology can also be used to handle a large number of invalid links and expired bookmarks due to site directory adjustments or other reasons.