日期:2014-05-18 浏览次数:20731 次
protected override void Render(HtmlTextWriter writer) { string name = Request.Url.AbsolutePath.Substring(1, Request.Url.AbsolutePath.Length - 1).Replace("aspx", "html"); name = name.ToLower().Replace("aspx/", ""); string newurl = ""; if (name.IndexOf("/") > 0) { newurl = Server.MapPath("/") + name; } else { newurl = Server.MapPath("/") + name; } MemoryStream ms = new MemoryStream(); StreamWriter sww = new StreamWriter(ms); StreamWriter swr = new StreamWriter(newurl); HtmlTextWriter htmlw = new HtmlTextWriter(swr); base.Render(htmlw); htmlw.Flush(); htmlw.Close(); string strLL = System.Text.Encoding.UTF8.GetString(ms.ToArray()); Response.Write(strLL); string tourl = Request.Url.AbsoluteUri.ToLower().Replace(".aspx", "htm").Replace("aspx/", ""); Response.Redirect(tourl, true); }
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" /> configSections节点后 <RewriterConfig> <Rules> <RewriterRule> <LookFor><![CDATA[~/(\d+)\.htm]]></LookFor> <SendTo><![CDATA[~/index.aspx?pageNum=$1]]></SendTo> </RewriterRule> </Rules> </RewriterConfig> system.web节点里 <httpModules> <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" /> </httpModules>