Methods of pseudo-static implementation of C #

Source: Internet
Author: User
Tags cdata

In the Web development site, we often use pseudo-static, the advantage is to hide the real path, improve the security of the site, on the website and other display sites want to search engine friendly, improve search rankings, or when it comes to template development will use pseudo-static. The following is an explanation of the pseudo-static implementation method used in peacetime.

One, method one:

Using Urlrewriter.dll:http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/msdnurlrewriting.msi

1 Add the URLRewriter.dll file reference in the startup file, and then add The code under the Config node

<configSections>    <section name="rewriterconfig" type= " URLRewriter.Config.RewriterConfigSerializerSectionHandler, Urlrewriter"/>    </ Sectiongroup>  </configSections>

2 Add code under the system.web node

<compilation>
<buildProviders>
<add extension= ". html" type= "System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>

"*"Path="*.html"Type="System.Web.UI.PageHandlerFactory"/> "Urlrewriter.modulerewriter, Urlrewriter"Name="Modulerewriter"/>

3 Add a rewrite URL code (regular expression) under the Configuration node

<RewriterConfig>    <Rules>              <RewriterRule>        <lookfor><![ cdata[~/shop/(\w+)?] ></LookFor>        <sendto><![ cdata[~/vshop/wechat/order/index.aspx?uid=$1]]></sendto>      </RewriterRule>            < Rewriterrule>        <lookfor><![ cdata[~/tupian/(\d+)/.html]]></lookfor>        <sendto><![ cdata[~/web/admin/other/$1.ashx]]></sendto>      </RewriterRule>            </Rules>  </RewriterConfig>

Second, method two
Starting with the. net3.5 version, the System.Web.Routing is available, and the program can write its own pseudo-static method

Add a ReWriteUrl.cs file with the following code:

PublicClassRewriteurl:iroutehandler {public string urlrote { get; private set;} Public Rewriteurl (string surlrote) {urlrote = surlrote;} public IHttpHandler Gethttphandler (RequestContext requestcontext) { return Buildmanager.createinstancefromvirtualpath (Urlrote, typeof (IHttpHandler)) as IHttpHandler;}}  

In the Application_Start function under the Global.asax.cs file

protected void Application_Start (object  sender, EventArgs e)        {            new Route ("  xxxx.html"new Rewriteurl ("~/xxxx.ashx")); //Address rewriting        }

. NET technology Exchange QQ Group: 320128737

Methods of pseudo-static implementation of C #

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.