. NET URL Rewriting usage instructions

Source: Internet
Author: User
Tags add browser redirect iis net
URL rewriting, this seems familiar, and feel very unfamiliar with the technology, has been with information security and SEO (Search Engine optimization) footsteps, gradually affect each Web Developer, no matter what technology you go, Basically it's hard not to take it seriously, because it can actually help you a lot. Just a rest URL style can make a lot of people's eyes bright.

Just imagine if your site has a URL that is long so good-looking:
Http://www.alixixi,com/System/plus/search.php?kwtype=1&keyword=%CD%F8%D5%BE&searchtype=titlekeyword

Still looks like this:
Http://webdesign.alixixi,com/xindejiqiao/200904/30-2010.html

Alternatively, can the user use such an input URL to:
http://www.alixixi,com/tag/j2ee/

To make a list of what he wants to search for, or to use, the user:
Http://www.alixixi,com/System/plus/search.php?kwtype=1&keywordj2ee&searchtype=titlekeyword such a URL?

I think the answer is obvious to people who have a concept of marketing or consumer behavior.

URL rewriting strengths, is the appearance of the URL, converted into the internal view of the URL to do processing, you can let the internal URL to continue to use, but also to allow the external URL affinity, so the URL Rewriting is now becoming one of the technologies that Web developers must know, and there are already many URLs rewriting modules available, such as urlrewriting.net, or the URL in IIS 7.0 Rewriting module and so on.

However, if you can walk on your own, you will know more about the URL rewriting, and for the network URL rewriting module, will be more accurate grasp (the following asp.net for the main description of the technology, other languages please refer to the manual, find the corresponding function).

First, the URL rewriting is a translator required for external and internal URLs, it needs to filter all URLs to perform the redirection, so it is better suited to live in the Web server's execution, ASP.net, using HTTP Module can handle this work (HTTP handler is less appropriate).

Receiving, Set up to handle httpapplication.beginrequest or Httpapplication.authorizerequest events (most modules are handled by httpapplication.authorizerequest events):

public void Init (HttpApplication context) {context.   AuthorizeRequest + = new EventHandler (appauthorizerequest); }
Then in the event literal, call HttpApplication.Context.RewritePath () to:

public void Appauthorizerequest (object sender, EventArgs e) {(sender as HttpApplication).   Context.rewritepath ("~/myhandler.aspx"); }
Then, in Web.config, hang the module in the System.web/httpmodules setting, and in the case of IIS 7.0, set it in System.webserver/modules.

<system.webServer> <validation validateintegratedmodeconfiguration= "false"/> <modules> <add name= "Urlrewritinghandler" type= "Urlrewritingmodule"/> </modules> </system.webserve R>
Then execute the Web application, no matter which URL path you enter, will be directed to the myhandler.aspx (of course, your project should have myhandler.aspx this page).

URL rewriting is actually technically the case, through the HttpApplication.Context.RewritePath () to the required URL to the specified page to deal with, however, in the development of practical, the URL There are a lot of rewriting to consider:

Since each URL is processed, what if the URL points to a picture, file, scripts, or other resource? Is there a special path to exclude? When the URL rewriting is executed, how will the URL format be designed to meet the requirements? What to do if the,<form> Action property responds to an internal URL rather than an external URL when the URL is overridden?

The URL rewriting is very efficient because it handles every URL requirement, not selectivity.

In addition, the URL is not necessarily hard to do rewriting, part of the need to eliminate the need to do rewriting, or you have some form of URL is to do redirect (HTTP 302), you can also directly output HTTP 302 message Request browser redirect can, remember, Do not add too many criteria in the URL rewriting, and do not do too much time in the URL rewriting, it will only slow down the processing speed of the URL (for example, even the database access data such things).



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.