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

xiaoxiao2021-03-06  27

When we were inquiring, we always transfer 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 // url using regular expression parsing Regex regex = new Regex (@ "page (/ D ). aspx ", regexoptions.ignorecase | regexoptions.ignorepatternwhitespace); matchcollection matches = regex.matches (ilpath); if (matches.count> 0) {// If condition is met, rewritten, generate the corresponding band parameters URL mode. PageID = matches [0] .Groups [1] .tostring (); incoming.rewritepath ("process.aspx? Pageid =" pageID);}} The next is to make a corresponding dynamic page. <% String pageid = request.QueryString ["pageid"]; // Create The page Content Based on this pageid taken here%> can come to access the test page I do. 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 doesn't use this mechanism? Originally visited here. Http://www.stardeveloper.com/articles/display.html?article=2004022801

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

New Post(0)