How to Implement pseudo-static. NET

Source: Internet
Author: User
Tags cdata
Http://msdn.microsoft.com/zh-cn/library/ms972974.aspx

How to Implement pseudo-static. NET

In fact, the so-called pseudo-static page refers to URL rewriting, in ASP. NET implementation is very simple first you need to reference two DLL: ActionlessForm. dll URLRewriter. what dll actually implements is URLRewriter. dll, but if you want to implement paging, you must use this ActionlessForm. dll first in the web. to write configSec in config, the so-called pseudo-static page refers to URL rewriting. In ASP. NET implementation is very simple

First, you need to reference two DLL files in your project:

ActionlessForm. dll

URLRewriter. dll

The actual rewrite is URLRewriter. dll. But if you want to implement paging, you must use this ActionlessForm. dll

First, write in web. config

<ConfigSections>

<Section type = "URLRewriter. Config. RewriterConfigSerializerSecti/>

</HttpModules>

<! -- The following is the URL rewrite rule -->

<RewriterConfig>

<Rules>

<RewriterRule>

<LookFor> ~ /Products/Jurisdiction _ (\ w {3}) \. aspx </LookFor>

<SendTo> ~ /En/Jurisdiction. aspx? Jurid = $1 </SendTo>

</RewriterRule>

<RewriterRule>

<LookFor> ~ /Articles/(\ d {1,}) \. aspx </LookFor> <! -- This is the replaced file name, which uses a regular expression -->

<SendTo> <! [CDATA [~ /En/Article_view.aspx? Article_id = $1]> </SendTo> <! -- This is a webpage to be replaced, generally a webpage with parameters following a question mark -->

</RewriterRule>

<RewriterRule>

<LookFor> ~ /Articles/(\ d {1,}) _ (\ d {1,}) \. aspx </LookFor>

<SendTo> <! [CDATA [~ /En/Article_view.aspx? Article_id = $1 & page = $2]> </SendTo>

</RewriterRule>

</Rules>

</RewriterConfig>

For example, the above URL http: // localhost/En/Article_View.aspx? You can use http: // localhost/Articles/9. aspx can be replaced. Of course, you can replace the extension with any extension that can be interpreted by iis. If you prefer to use htm as the extension, configure htm as the extension above the forwarding rule, some articles may also be very long. We usually divide an article into several pages. Based on the above configuration, if we want to access http: // localhost/En/Article_View.aspx? Article_id = 9 & page = 3 we can use http: // localhost/Articles/9_3.aspx instead, so that when the search engine grabs your webpage, you will be included in these URLs. When someone else searches your webpage, they will be able to access these URLs.

Then, perform the following operations:

Right-click my computer --> Manage --> Expand 'services and Applications' --> internet Information Service --> Find the directory you shared --> right-click Properties --> click 'configuration' -->

Ing the following --> Find. aspx executable file path copy path --> paste path --> the extension is ". html "--> then remove the check object check box to check whether the object exists.

2: Environment: windows XP Professional

Development Platform: NET2.0, VS2005

Has been tested to implement pseudo-static technology, such as Show. aspx? The conversion from myid1_1success to 1.html is now shared with you:

Introduction: Why don't we directly use Show. aspx? Myid1_1 is a simple access method, rather than using access methods like 1.html. Many people may feel that it is not necessary to explain it again, but younger brother is also a beginner. Considering that many enthusiasts of the same level as me have been worried about this, this article is only intended for cainiao compatriots who wish to help you. As for the audience who have seen it, I hope to provide more valuable opinions or suggestions, I would like to encourage this shrimp, and provide more simple, more common, and more practical methods for the shrimps with more dishes !!!

①: First, you need to have this file URLRewriter. dll. If not, download it online, put it in the bin directory below, and add its reference to the following;

②: Below is the configuration of the Web. Config file. Of course, the configuration process is quite simple:

1: add this

<ConfigSections>

<Section type = "URLRewriter. Config. RewriterConfigSerializerS ectionHandler, URLRewriter"/>

</ConfigSections>

<RewriterConfig>

<Rules>

<! -- Rules for Blog Content Displayer -->

<RewriterRule>

<LookFor> ~ /(. [0-9] *) \. html </LookFor>

<SendTo> ~ /ArticleDetail. aspx? MyID = $1 </SendTo>

</RewriterRule>

</Rules>

</RewriterConfig>

2: add this

<HttpHandlers>

<Add verb = "*" path = "*. aspx" type = "URLRewriter. RewriterFactoryHandler, URLRewriter"/>

<Add verb = "*" path = "*. html" type = "URLRewriter. RewriterFactoryHandler, URLRewriter"/>

</HttpHandlers>

At this point, more than half of the projects have been successfully added to Web. Config. It seems unnecessary to add them to any location!

Last step: Find your virtual directory website in IIS, click Properties, click Configure, and then pop up the application configuration dialog box, select add, and add the executable file path to c: \ windows \ microsoft.net \ framework \ v2.0.50727 \ aspn et_isapi.dll, extended name: .html

3:

We sometimes see this address: "http://www.yiuu.net/show-12-34.html", you might think there is a file named "show-12-34.html" under the root directory of the Site Server, actually, it may not exist, but you may see "/aspx/show. aspx? Type = 12 & id = 34 ", why? There are multiple reasons: First, enhance the friendliness of the URL, remember "show-12-34.html" ratio "/aspx/show. aspx? Type = 12 & id = 34 "Easy to remember? The second is to facilitate search engine indexing. Many search engines prefer static HTML pages, such as Baidu. The second is for security reasons, because the parameters "type" and "id" are hidden ". Is it interesting?

In fact, this is implemented using URL rewriting. Next I will talk about it in ASP. what I know in NET2.0 is the simplest implementation method: The Implementation interface "IHttpHandler" is used to take over HTTP requests, Follow me!

1. Add a class to the resource management solution. The code of the class is as follows:

// List of URLRewriter programs:

Using System;

Using System. Data;

Using System. Configuration;

Using System. Web;

Using System. Web. Security;

Using System. Web. UI;

Using System. Web. UI. WebControls;

Using System. Web. UI. WebControls. WebParts;

Using System. Web. UI. HtmlControls;

/// <Summary>

/// UrlRewriter URL rewriting class

/// Author: KID

// Blog: http://www.yiuu.net

/// </Summary>

Public class UrlRewriter: IHttpHandler // implements the "IHttpHandler" Interface

{

Public UrlRewriter ()

{

//

// TODO: add the constructor logic here

//

}

Public void ProcessRequest (HttpContext Context)

{

Try

{

// Obtain the original URL blocking Parameter

String Url = Context. Request. RawUrl;

// Create a regular expression

System. text. regularExpressions. regex Reg = new System. text. regularExpressions. regex (@ "/show-(\ d + )\.. + ", System. text. regularExpressions. regexOpt ions. ignoreCase );

// Match with a regular expression

System. Text. RegularExpressions. Match m = Reg. Match (Url, Url. LastIndexOf ("/"); // Match from the last "/"

If (m. Success) // match successful

{

// Context. Response. Write (@"~ /Aspx/show. aspx? Type = "+ m. Groups [1] + "&~ /Aspx/show. aspx? Members required for the type = "+ m. Groups [1] +" & IHttpHandler "Interface

/// </Summary>

/// <Value> </value>

Public bool IsReusable

{

Get {return false ;}

}

}

2. Add the setting items in the web. config file.

Add the following code under the <system. web> node:

<HttpHandlers>

<Add verb = "*" path = "*/show -? *-? *. Aspx "type =" UrlRewriter "/>

</HttpHandlers>

[Edit Huoho. Com]

Explanations:

Verb indicates one or more of the permitted actions "GET", "POST", and "PUT". The asterisk "*" indicates that all actions are allowed;

A path is a matching path that supports Simple wildcards;

Type indicates the bound class name and namespace (if any );

By the way, you must first create a WEB form "show. aspx" in the directory "aspx", because this file is a page that actually accepts the request and displays the relevant content.

OK !, Compile, open the website input address http: // localhost: 80/show-12-34.aspx access, check to see if it is displayed "/aspx/show. aspx? What about type = 12 & id = 34 ?!

The above settings match the ASPX file, because in IIS. the default HTML extension is ASP. NET. If you want to take over HTML requests, set the IIS extension. HTML ing to "C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ asp net_isapi.dll ", and then change the above aspx to html:

<HttpHandlers>

<Add verb = "*" path = "*/show -? *-? *. Html "type =" UrlRewriter "/>

</HttpHandlers>

Open the website now and enter the address http: // localhost: 80/show-12-34.html to visit ~!

 

 

Asp.net pseudo-static sending and paging

ActionlessForm is the location of the pseudo-static link when the page is sent back, import <% @ Register TagPrefix = "skm" Namespace = "ActionlessForm" Assembly = "ActionlessForm" %> in the header of each page that implements pseudo-link, and rewrite FORM <skm: form id = "form1" method = "post" runat = "server"> </skm: form>.

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.