The URL escape control that you are using (with source code)

Source: Internet
Author: User
I forgot how the source code came from. It seems to be from Microsoft. Later I thought the configuration was too cumbersome and inconvenient to use.
I changed it slightly. I will report it at the beginning. You will give me some comments.

Usage:
1.
Web. config
Add:
<? XML version = "1.0"?>
<Configuration>
<System. Web>
<Httpmodules>
<Add name = "modulerewriter" type = "jiaolg. urlrewriter. modulerewriter, urlrewriter"/>
</Httpmodules>
</System. Web>
</Configuration>

2.
Copy urlrewriter. DLL to the bin directory.

3.
Copy rewriter. XML to app_data

Some source code: UsingSystem;
UsingSystem. Web;
UsingSystem. Web. caching;
UsingSystem. xml;
UsingSystem. Text. regularexpressions;

Namespace Jiaolg. urlrewriter
{
Public   Class Modulerewriter: basemodulerewriter
{
Private   Static   Readonly   String Cname =   " Rules " ;
Private Xmlnodelist rules;

protected override void rewrite ( string requestedpath, system. web. httpapplication APP)
{< br> app. context. trace. write ( " modulerewriter " , " entering modulerewriter " );

If (Httpruntime. cache [cname] =   Null )
{
Cachedependency CD =   New Cachedependency (rules. configfile );

Rules =   New Rules (). getrules ();
Httpruntime. cache. insert (cname, rules, Cd );
}
Else
{
Rules = (Xmlnodelist) httpruntime. cache [cname];
}

// Iterate through each rule
Foreach (Xmlnode rule In Rules)
{
String Lf = Rule. firstchild. selectsinglenode ( " Lookfor " ). Innertext;
String St = Rule. firstchild. selectsinglenode ( " Sendto " ). Innertext;
String Lookfor =   " ^ "   + Rewriterutils. resolveurl (App. Context. Request. applicationpath, LF) +   " $ " ;

RegEx re= NewRegEx (lookfor, regexoptions. ignorecase );

If (Re. ismatch (requestedpath)
{< br> string sendtourl = rewriterutils. resolveurl (App. context. request. applicationpath, re. replace (requestedpath, St);

app. context. trace. write ( " modulerewriter " , " rewriting URL to " + sendtourl );

rewriterutils. rewriteurl (App. context, sendtourl);
Break ;
}< BR >}

App. Context. Trace. Write ("Modulerewriter","Exiting modulerewriter");
}
}
}

Download (including source code ):
Urlrewriter.zip

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.