String newurl = GetUrl (cxt, path. TrimEnd (). TrimStart ());
if (Newurl!= null)
{
Cxt. Response.filter = new Responsefilter (CXT. Response.filter,cxt. Request.path);
Cxt. Response.Write ("Path of the request:" + path);
Cxt. Response.Write ("<BR>");
Cxt. Response.Write ("The purpose of the steering URL:" + newurl);
Cxt. Response.Write ("<BR>");
Cxt. RewritePath (Newurl);
}//If you require all requests to be processed
Else
//{
Cxt. Response.Write (CXT. Request.path + "<BR>");
Cxt. Response.Write ("The resources you requested do not exist or have no access!") ");
Cxt. Response.Flush ();
Cxt. Response.End ();
//}
}
};
}
}
Because once the URL is rewritten, the action in the original WebForm changes, which is easy: the requested resource does not have a problem
How exactly? I'll see you in DX,!!!.
All this responsefilter has been achieved, as follows,
public class ResponseFilter:System.IO.Stream
{
Public Responsefilter (System.IO.Stream sink,string _str)
{
_sink = sink;
//
TODO: Add constructor logic here
//
This.str = _str;
}
private string str = "";
Private System.IO.Stream _sink;
Private long _position;
Private System.Text.Encoding end=system.text.encoding.getencoding ("GB18030");
Private System.Text.StringBuilder ooutput = new System.Text.StringBuilder ();
The following members of the Stream must are overriden.
public override bool CanRead
{
get {return true;}
}
public override bool CanSeek
{
get {return true;}
}
public override bool CanWrite
{
get {return true;}
}
public override Long Length
{
get {return 0;}
}
public override Long Position
{
get {return _position;}
set {_position = value;}
}
public override long (long offset, System.IO.SeekOrigin direction)
{
Return _sink. Seek (offset, direction);
}
The following paragraph can be used to modify the content between <Head>Regex oendfile = new Regex ("if (Oendfile.ismatch (szbuffer))
//{
Append the last buffer of data
Append last piece of data from the upper buffer
Ooutput.append (Szbuffer);
Get back the complete response for the client
Returns the full client return data
String szcompletebuffer = Ooutput.tostring (). ToLower ();
int ipos = Szcompletebuffer.indexof ("<title>");
int epos = Szcompletebuffer.indexof ("</title>", ipos+7);
String sp = Szcompletebuffer.substring (ipos+7, Epos-ipos);
Szcompletebuffer = Szcompletebuffer.remove (ipos+7,sp. LENGTH-7);
Szcompletebuffer = Szcompletebuffer.insert (ipos + 7, "dhz");
Szcompletebuffer = Szcompletebuffer.replace (sp, "dhz");
No match, so write out original data
No match, so write source code
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes (Szcompletebuffer);
_sink. Write (data, 0, data. Length);
//}
Else
//{
Ooutput.append (Szbuffer);
//}
}
}
And the heavy-weather rules are configured with XML files as follows;
Of course, it's OK to do it in Web.config by customizing the configuration section.
<?xml version= "1.0" encoding= "Utf-8"?>
<Rules>
<RewriterRule>
<LookFors>
<lookfor>~/(\d{4})/(\d{2}) \.html</lookfor>
<lookfor>~/(\d{4})/(\d{2})/</lookfor>
<lookfor>~/(\d{4})/(\d{2}) </LookFor>
<lookfor>~/(\d{4})/(\d{2})/index.html</lookfor>
</LookFors>
<SendTo>~/Pro.aspx?year=$1&month=$2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFors>
<LookFor>~/pc</LookFor>
</LookFors>
<SendTo>~/Test2.aspx</SendTo>
</RewriterRule>
</Rules>
This rule is poorly written, as the first one can be done with a regular expression.
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.