在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
URL 重写是截取传入 Web 请求并自动将请求重定向到其他 URL 的过程。 <?xml version="1.0" encoding="utf-8" ?>
<!--overred--> <configuration> <configSections> <section name="RewriterConfig"type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" /> </configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/d(\d+)\.aspx</LookFor> <SendTo>~/default.aspx?id=$1</SendTo> </RewriterRule> </Rules> </RewriterConfig> <system.web> <httpHandlers> <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> </httpHandlers> </system.web> </configuration>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
<LookFor>~/d(\d+)\.aspx</LookFor>
<SendTo>~/default.aspx?id=$1</SendTo> <LookFor>~/d(\d+)\.aspx</LookFor>
表示,用户输入的url,d(\d+)\.aspx是 url中文件名匹配的正则表达式(此处为字母d开头,后面跟一个或多个数字,并以.aspx结尾。用户也可根据自己的需要自行设定)。 <SendTo>~/default.aspx?id=$1</SendTo>
,表示当服务器接收到符合上面条件的请求后如何重写url。此处表示访问defalutl.aspx并传入参数id,其值$1将用用户请求的文件名中的第一个数字来表示。 namespace ActionlessForm
{ public class Form : System.Web.UI.HtmlControls.HtmlForm { protected override void RenderAttributes(HtmlTextWriter writer) { writer.WriteAttribute("name", this.Name); base.Attributes.Remove("name"); writer.WriteAttribute("method", this.Method); base.Attributes.Remove("method"); this.Attributes.Render(writer); base.Attributes.Remove("action"); if (base.ID != null) writer.WriteAttribute("id", base.ClientID); } } }
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
using System;
using System.IO; using System.Web; using System.Web.UI; namespace URL { public class OLPage : Page { public OLPage() {} protected override void Render(HtmlTextWriter writer) { if (writer is System.Web.UI.Html32TextWriter) { writer = new FormFixerHtml32TextWriter(writer.InnerWriter); } else { writer = new FormFixerHtmlTextWriter(writer.InnerWriter); } base.Render(writer); } } internal class FormFixerHtml32TextWriter : System.Web.UI.Html32TextWriter { private string _url; // 假的URL internal FormFixerHtml32TextWriter(TextWriter writer):base(writer)} } internal class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter}
public class WebForm1:page
public class WebForm1:URL.OLPage
|
请发表评论