ASP. NET create pseudo-static page

Source: Internet
Author: User

The following is my study for several days with colleagues to study out, original.

1 pseudo-static definition:

Pseudo-Static is relatively true static, usually we to enhance the search engine friendly side, will be the article content generated static pages, but some friends in order to display some information in real time. Or you want to use dynamic scripting to solve some problems. You cannot display site content in a static manner. But this loses the friendly side of the search engine. How to find a middle method between the two, which produces pseudo-static technology. Is the display of a static page in the form of HTML, but in fact, a class of ASP dynamic script to deal with.

2 pseudo-Static implementations:

2.1 Create URL rewrite class URLRewiter.cs code as follows:

1 usingSystem;2 usingSystem.Data;3 usingSystem.Configuration;4 usingsystem.web;5 usingSystem.Web.Security;6 usingSystem.Web.UI;7 usingSystem.Web.UI.WebControls;8 usingSystem.Web.UI.WebControls.WebParts;9 usingSystem.Web.UI.HtmlControls;Ten namespaceWebApplication1 One { A      Public classUrlrewiter:ihttphandler -     { -          PublicUrlrewiter () the         { -         //TODO: Add constructor logic here -           } -          Public voidProcessRequest (HttpContext Context) +         { -             Try +             { A                 //get the original URL mask off parameters at                 stringURL =Context.Request.RawUrl; -                 //Establish regular Expressions -System.Text.RegularExpressions.Regex Reg =NewSystem.Text.RegularExpressions.Regex -(@"/show-(\d+) \. +", System.Text.RegularExpressions.RegexOptions.IgnoreCase); -                 //match with regular expressions -System.Text.RegularExpressions.Match m = Reg.match (Url, Url.lastindexof ("/"));//start matching from the last "/" in                 if(m.success)//Match Success -                 { toString Realpath =@"~/aspx/show.aspx?type="+ m.groups[1]; + Context.Server.Execute (realpath); -                 } the                 Else *                 { $ Context.Response.Redirect (Context.Request.Url.ToString ());Panax Notoginseng                 } -             } the             Catch +             { A Context.Response.Redirect (Context.Request.Url.ToString ()); the             } +         } -  $         /// <summary> $         ///members required to implement the "IHttpHandler" interface -         /// </summary> -         /// <value></value> the         ///Author:yoyo -         ///Blog:http://yangmingsheng.cnWuyi          Public BOOLisreusable the         { -             Get{return false; } Wu         } -     } About}
View Code

The 2.2web.config code is as follows:

1 <httphandlers>2         <Addverb="*"Path= "*/show-?*.aspx"type= "Webapplication1.urlrewiter" />3         <Addverb="*"Path= "*/show-?*.html"type= "Webapplication1.urlrewiter" />4 </httphandlers>

There are no problems with local browsing so far:

Http://localhost:56321/aspx/show.aspx----can be changed to the following address as the effect, representing the Local has succeeded.

Http://localhost:56321/aspx/show-9.html

3 Next is the configuration of IIS. (Mine is Win7 32-bit system IIS7)

3.1 Publish your program to IIS as you would normally publish to see if you can access it.

3.2 Select your application, double-click the "handler image" in the room, and then tap on the right "add script map" as:

Request Path: *.html

Executable: C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll (note 64-bit system into Framework64 folder)

Name Random:

3.3 Then click "Add Wildcard Script map" on the right.

Request path Regardless, the executable file is the same as the handler image, and the name is also arbitrary.

4. Has been successfully configured so far, note that the above code configuration format is show-9.html, that is, there is only one integer after the minus sign, this can modify the rule.

Thank you!

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.