ASP.NET creates links to search engines to be friendly access

xiaoxiao2021-03-06  42

Author: http: //www.donews.net/lealting/archive/2004/03/31/9759.aspx Today saw an article mainly about how to make search engines can link a friendly visit, probably content This is this: When we are inquiring, we will always pass parameters in such a link:

http://www.yoursite.com/query.aspx?typeid=2

This link is very clear that I want to see the information about the related records of TypeId = 2.

But this is a problem that the SPIDER of the search engine is difficult to analyze the URL, because it does not understand this way of parameters.

If desired, the results of the database query corresponding to each TypeID can be easily recorded by the search engine, and we may need to write such a connection.

http://www.yoursite.com/pagetype1.aspx

http://www.yoursite.com/pagetype2.aspx

And so on.

According to the usual idea, this requires writing N such a page, quite cumbersome.

However, in the ASP.NET, the URL converts the URL transformation can be used to convert the static page URL as a parameter dynamic page URL], you can easily solve such problems. Please see the following code:

Protected Void Application_BeginRequest (Object Sender, Eventargs E)

{

HttpContext incoming = httpContext.current;

String oldpath = incoming.Request.path.tolower ();

String pageId; // page id requested

// Eliminate the URL using the regular expression

Regex regex = new regex (@ "Page (/ D ). ASPX", RegexOptions.Ignorecase |

Regexoptions.ignorePatternwhitespace);

Matchcollection matches = regex.matches (OldPath);

IF (Matches.count> 0)

{

// If the condition is met, it is rewritten to generate the corresponding URL mode with the corresponding parameter.

PageID = matches [0] .Groups [1] .tostring ();

INCOMING.REWRITEPATH ("Process.aspx? pageid =" pageID);

}

}

Next, you need to do a corresponding dynamic page.

<%

String pageId = request.querystring ["pageid"];

// Create The page Content Based on this pageid taken here

%>

Can come to visit the test page I have made. Please modify the numbers behind the page.

http://lealting.europe.webmatrixhosting.net/page11.aspx

http://lealting.europe.webmatrixhosting.net/page22.aspx

I think the blog uses this mechanism?

Originally visited here.

转载请注明原文地址:https://www.9cbs.com/read-72762.html

New Post(0)