重写前:http://localhost:13275/Default.aspx?username=wilson
重写后:http://localhost:13275/wilson
<browsers> <browser refID="Default"> <controlAdapters> <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="URLRewriter.Form.FormRewriterControlAdapter" /> </controlAdapters> </browser> </browsers>
<configSections> <section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter"/> </configSections> <CustomConfiguration> <urls> <!--([\w]+)表示,1到n个字母或数字或下划线或汉字组成--> <add virtualUrl="~/([\w]+)*" destinationUrl="~/Default.aspx?username=$1"/> </urls> </CustomConfiguration>
<httpModules> <add type="URLRewriter.RewriterModule, URLRewriter" name="RewriterModule"/> </httpModules>
if (!IsPostBack) { StringBuilder sb = new StringBuilder(); sb.Append("当前所在位置:Default.aspx<br/>"); if (!string.IsNullOrEmpty(Request.Params["username"])) { sb.Append("所接收到的参数username:" + Request.Params["username"]); } Response.Write(sb.ToString()); }