- 浏览: 1818580 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
yeying12:
强大
HTTP协议详解,你所不知道的 -
夏雪纷纷:
据我所知,9月12日有个对于DXperience 2013新功 ...
DXperience 9.1.3 -
Emy:
现在面临第一个坎。。
IT高薪者所具备的人格魅力 -
yangxiutian:
很详细,楼主很会总结。
IE下 z-index 的各种坑 -
idleone:
真心求指教,全选怎么实现
Android开发之ListView,加入CheckBox(复选框),实现选择列表
url重写
<font size="2">URL 重写是截取传入 Web 请求并自动将请求重定向到其他 URL 的过程。<br> 比如浏览器发来请求hostname/101.aspx ,服务器自动将这个请求中定向为http://hostname/list.aspx?id=101。<br><br> url重写的优点在于:<br> 缩短url,隐藏实际路径提高安全性<br> 易于用户记忆和键入。 <br> 易于被搜索引擎收录<br><br></font><font size="2"> 二 实现url重写的基本方法<br> 下载MS的URLRewriter.dll,放到你的web程序的bin下<br> 下载地址1:http://www.rickel.cn/uploads/DevTools/MSDNURLRewriting.msi<br> 下载地址2:<a target="_blank" href="http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi"><font color="#800080">download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi</font></a><br><br> 下载完成后,在web.config里设置如下:<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><?</span><span style="color: rgb(255, 0, 255);">xmlversion="1.0"encoding="utf-8"</span><span style="color: rgb(0, 0, 255);">?></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 0);"><!--</span><span style="color: rgb(0, 128, 0);">overred</span><span style="color: rgb(0, 128, 0);">--></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">configSections</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">section</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="RewriterConfig"</span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 255);">/></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">configSections</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">RewriterConfig</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">Rules</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">RewriterRule</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/d(/d+)/.aspx</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/default.aspx?id=$1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">RewriterRule</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">Rules</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">RewriterConfig</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">system</span><span style="color: rgb(255, 0, 0);">.web</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">httpHandlers</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">add</span><span style="color: rgb(255, 0, 0);">verb</span><span style="color: rgb(0, 0, 255);">="*"</span><span style="color: rgb(255, 0, 0);">path</span><span style="color: rgb(0, 0, 255);">="*.aspx" </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="URLRewriter.RewriterFactoryHandler,URLRewriter"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 255);">/></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">httpHandlers</span><span style="color: rgb(0, 0, 255);">><br></span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">system</span><span style="color: rgb(255, 0, 0);">.web</span><span style="color: rgb(0, 0, 255);">><br></span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">></span><br></font>
</div>
<font size="2"><br><br> 其中<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">section</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="RewriterConfig" </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 255);">/></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"><br></span><span style="color: rgb(0, 0, 255);"></span></font>
</div>
<font size="2"><br> 用于指定配置节"RewriterConfig"的处理程序类的名称为”URLRewriter.Config.RewriterConfigSerializerSectionHandler”,该类存在于bin目录下的URLRewriter .dll文件中<br><br>关键的是这两句<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/d(/d+)/.aspx</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/default.aspx?id=$1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span></font>
</div>
<font size="2"><br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/d(/d+)/.aspx</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span></font>
</div>
<font size="2">表示,用户输入的url,d(/d+)/.aspx是 url中文件名匹配的正则表达式(此处为字母d开头,后面跟一个或多个数字,并以.aspx结尾。用户也可根据自己的需要自行设定)。<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/default.aspx?id=$1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span></font>
</div>
<font size="2">,表示当服务器接收到符合上面条件的请求后如何重 写url。此处表示访问defalutl.aspx并传入参数id,其值$1将用用户请求的文件名中的第一个数字来表示。<br> 例如用户输入 hostname/d11.aspx, 服务器会把他重写为http://hostname/default.aspx?id=11。换句话说用户输入http: //hostname/d11.aspx,实际访问的是http://hostname/default.aspx?id=11。这样就起到了隐藏真实文件名,并便于用户记忆的作用。<br><br><strong>处理回发</strong><br> 在重写后的url里如果产生回发,例如有一个按钮,又调用了该被重写的aspx,用户浏览器中将会显示该aspx文件实际的地址,也就是http: //hostname/default.aspx?id=11。但从用户的角度考虑,如 果单击按钮时突然看到 URL 更改会使他们感到不安。因此必须解决这个问题。<br> 解决方法有二:<br> (1)自己定义一个Actionlessform类,在aspx中不再使用系统提供的form 标记<br><br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">ActionlessForm <br>{<br></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">Form:System.Web.UI.HtmlControls.HtmlForm<br> {<br></span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">RenderAttributes(HtmlTextWriterwriter)<br> {<br> writer.WriteAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.Name);<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Attributes.Remove(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br> writer.WriteAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">method</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.Method);<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Attributes.Remove(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">method</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br></span><span style="color: rgb(0, 0, 255);"> this</span><span style="color: rgb(0, 0, 0);">.Attributes.Render(writer);<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Attributes.Remove(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">action</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">.ID</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br> writer.WriteAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">.ClientID);<br> }<br> }<br>}</span></font>
</div>
<font size="2"><br><br> 创建此类并对其进行编译之后,要在 ASP.NET Web 应用程序中使用它,应首先将其添加到 Web 应用程序的 References 文件夹中。然后,要使用它来代替 HtmlForm 类,做法是在 ASP.NET 网页的顶部添加以下内容:<br><br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);"><%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@RegisterTagPrefix</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">skm</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">Namespace</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">ActionlessForm</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">" </span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">Assembly</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">ActionlessForm</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"></span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%></span></font>
</div>
<font size="2"><br> 然后,将 <form runat="server">(如果有)替换为:<skm:Form id="Form1" method="post" runat="server"> <br> 并将右边的 </form> 标记替换为:</skm:Form><br><br><strong>个人并不推荐该方法</strong><br> (2)第二种方法就是继承page,这样你不需要在aspx页中改任何东西。<br> 代码:<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System.IO;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System.Web;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System.Web.UI;<br></span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">URL<br>{<br></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">OLPage:Page<br> {<br></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);">OLPage()<br> {}<br></span><span style="color: rgb(0, 0, 255);"> protected</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">Render(HtmlTextWriterwriter)<br> {<br></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(writer</span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);">System.Web.UI.Html32TextWriter)<br> {<br> writer</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">FormFixerHtml32TextWriter(writer.InnerWriter);<br> }<br></span><span style="color: rgb(0, 0, 255);"> else</span><span style="color: rgb(0, 0, 0);"><br> {<br> writer</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">FormFixerHtmlTextWriter(writer.InnerWriter);<br> }<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Render(writer);<br> }<br> }<br><br></span><span style="color: rgb(0, 0, 255);"> internal</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">FormFixerHtml32TextWriter:System.Web.UI.Html32TextWriter<br> {</span><span style="color: rgb(0, 0, 255);"><br> private</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">_url;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">假的URL</span><span style="color: rgb(0, 128, 0);"></span><br></font><blockquote><font size="2"><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 255);"> internal</span><span style="color: rgb(0, 0, 0);">FormFixerHtml32TextWriter(TextWriterwriter):</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">(writer)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> _url</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">HttpContext.Current.Request.RawUrl;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">WriteAttribute(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">name,</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">value,</span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);">encode)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(_url</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">&&</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Compare(name,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">action</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">_url;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.WriteAttribute(name,value,encode);</span><br><span style="color: rgb(0, 0, 0);"></span></font></blockquote>
<font size="2"><span style="color: rgb(0, 0, 0);"> }<br> }<br></span></font><blockquote><font size="2"><span style="color: rgb(0, 0, 255);">internal</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">FormFixerHtmlTextWriter:System.Web.UI.HtmlTextWriter</span><br><span style="color: rgb(0, 0, 0);">{</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> private</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">_url;</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> internal</span><span style="color: rgb(0, 0, 0);">FormFixerHtmlTextWriter(TextWriterwriter):</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">(writer)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> _url</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">HttpContext.Current.Request.RawUrl;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> </span><br><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">WriteAttribute(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">name,</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">value,</span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);">encode)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(_url</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">&&</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Compare(name,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">action</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">_url;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.WriteAttribute(name,value,encode);</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);">}</span><br><span style="color: rgb(0, 0, 0);"></span></font></blockquote>
<font size="2"><span style="color: rgb(0, 0, 0);">}</span></font>
</div>
<font size="2"><br><br> 把这个文件编译成dll,并在你的项目中引用它。<br><br> 然后把项目中的所有aspx文件对应的cs文件中的继承page类的代码改写为继承OLPage。<br> 例如<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">WebForm1:page</span></font>
</div>
<font size="2"><br> 改写为<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">WebForm1:URL.OLPage</span></font>
</div>
<font size="2"><br><br> 这样就解决回发问题。</font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><?</span><span style="color: rgb(255, 0, 255);">xmlversion="1.0"encoding="utf-8"</span><span style="color: rgb(0, 0, 255);">?></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 0);"><!--</span><span style="color: rgb(0, 128, 0);">overred</span><span style="color: rgb(0, 128, 0);">--></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">configSections</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">section</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="RewriterConfig"</span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 255);">/></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">configSections</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">RewriterConfig</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">Rules</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">RewriterRule</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/d(/d+)/.aspx</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/default.aspx?id=$1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">RewriterRule</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">Rules</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">RewriterConfig</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">system</span><span style="color: rgb(255, 0, 0);">.web</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">httpHandlers</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> <</span><span style="color: rgb(128, 0, 0);">add</span><span style="color: rgb(255, 0, 0);">verb</span><span style="color: rgb(0, 0, 255);">="*"</span><span style="color: rgb(255, 0, 0);">path</span><span style="color: rgb(0, 0, 255);">="*.aspx" </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="URLRewriter.RewriterFactoryHandler,URLRewriter"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 255);">/></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"> </</span><span style="color: rgb(128, 0, 0);">httpHandlers</span><span style="color: rgb(0, 0, 255);">><br></span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">system</span><span style="color: rgb(255, 0, 0);">.web</span><span style="color: rgb(0, 0, 255);">><br></span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">></span><br></font>
</div>
<font size="2"><br><br> 其中<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">section</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="RewriterConfig" </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 255);">/></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"><br></span><span style="color: rgb(0, 0, 255);"></span></font>
</div>
<font size="2"><br> 用于指定配置节"RewriterConfig"的处理程序类的名称为”URLRewriter.Config.RewriterConfigSerializerSectionHandler”,该类存在于bin目录下的URLRewriter .dll文件中<br><br>关键的是这两句<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/d(/d+)/.aspx</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/default.aspx?id=$1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br></span></font>
</div>
<font size="2"><br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/d(/d+)/.aspx</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">LookFor</span><span style="color: rgb(0, 0, 255);">></span></font>
</div>
<font size="2">表示,用户输入的url,d(/d+)/.aspx是 url中文件名匹配的正则表达式(此处为字母d开头,后面跟一个或多个数字,并以.aspx结尾。用户也可根据自己的需要自行设定)。<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">~/default.aspx?id=$1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">SendTo</span><span style="color: rgb(0, 0, 255);">></span></font>
</div>
<font size="2">,表示当服务器接收到符合上面条件的请求后如何重 写url。此处表示访问defalutl.aspx并传入参数id,其值$1将用用户请求的文件名中的第一个数字来表示。<br> 例如用户输入 hostname/d11.aspx, 服务器会把他重写为http://hostname/default.aspx?id=11。换句话说用户输入http: //hostname/d11.aspx,实际访问的是http://hostname/default.aspx?id=11。这样就起到了隐藏真实文件名,并便于用户记忆的作用。<br><br><strong>处理回发</strong><br> 在重写后的url里如果产生回发,例如有一个按钮,又调用了该被重写的aspx,用户浏览器中将会显示该aspx文件实际的地址,也就是http: //hostname/default.aspx?id=11。但从用户的角度考虑,如 果单击按钮时突然看到 URL 更改会使他们感到不安。因此必须解决这个问题。<br> 解决方法有二:<br> (1)自己定义一个Actionlessform类,在aspx中不再使用系统提供的form 标记<br><br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">ActionlessForm <br>{<br></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">Form:System.Web.UI.HtmlControls.HtmlForm<br> {<br></span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">RenderAttributes(HtmlTextWriterwriter)<br> {<br> writer.WriteAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.Name);<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Attributes.Remove(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br> writer.WriteAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">method</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.Method);<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Attributes.Remove(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">method</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br></span><span style="color: rgb(0, 0, 255);"> this</span><span style="color: rgb(0, 0, 0);">.Attributes.Render(writer);<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Attributes.Remove(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">action</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">.ID</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br> writer.WriteAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">.ClientID);<br> }<br> }<br>}</span></font>
</div>
<font size="2"><br><br> 创建此类并对其进行编译之后,要在 ASP.NET Web 应用程序中使用它,应首先将其添加到 Web 应用程序的 References 文件夹中。然后,要使用它来代替 HtmlForm 类,做法是在 ASP.NET 网页的顶部添加以下内容:<br><br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);"><%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@RegisterTagPrefix</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">skm</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">Namespace</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">ActionlessForm</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">" </span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">Assembly</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">ActionlessForm</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"></span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%></span></font>
</div>
<font size="2"><br> 然后,将 <form runat="server">(如果有)替换为:<skm:Form id="Form1" method="post" runat="server"> <br> 并将右边的 </form> 标记替换为:</skm:Form><br><br><strong>个人并不推荐该方法</strong><br> (2)第二种方法就是继承page,这样你不需要在aspx页中改任何东西。<br> 代码:<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System.IO;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System.Web;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">System.Web.UI;<br></span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">URL<br>{<br></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">OLPage:Page<br> {<br></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);">OLPage()<br> {}<br></span><span style="color: rgb(0, 0, 255);"> protected</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">Render(HtmlTextWriterwriter)<br> {<br></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(writer</span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);">System.Web.UI.Html32TextWriter)<br> {<br> writer</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">FormFixerHtml32TextWriter(writer.InnerWriter);<br> }<br></span><span style="color: rgb(0, 0, 255);"> else</span><span style="color: rgb(0, 0, 0);"><br> {<br> writer</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">FormFixerHtmlTextWriter(writer.InnerWriter);<br> }<br></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.Render(writer);<br> }<br> }<br><br></span><span style="color: rgb(0, 0, 255);"> internal</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">FormFixerHtml32TextWriter:System.Web.UI.Html32TextWriter<br> {</span><span style="color: rgb(0, 0, 255);"><br> private</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">_url;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">假的URL</span><span style="color: rgb(0, 128, 0);"></span><br></font><blockquote><font size="2"><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 255);"> internal</span><span style="color: rgb(0, 0, 0);">FormFixerHtml32TextWriter(TextWriterwriter):</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">(writer)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> _url</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">HttpContext.Current.Request.RawUrl;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">WriteAttribute(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">name,</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">value,</span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);">encode)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(_url</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">&&</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Compare(name,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">action</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">_url;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.WriteAttribute(name,value,encode);</span><br><span style="color: rgb(0, 0, 0);"></span></font></blockquote>
<font size="2"><span style="color: rgb(0, 0, 0);"> }<br> }<br></span></font><blockquote><font size="2"><span style="color: rgb(0, 0, 255);">internal</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">FormFixerHtmlTextWriter:System.Web.UI.HtmlTextWriter</span><br><span style="color: rgb(0, 0, 0);">{</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> private</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">_url;</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> internal</span><span style="color: rgb(0, 0, 0);">FormFixerHtmlTextWriter(TextWriterwriter):</span><span style="color: rgb(0, 0, 255);">base</span><span style="color: rgb(0, 0, 0);">(writer)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> _url</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">HttpContext.Current.Request.RawUrl;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> </span><br><span style="color: rgb(0, 0, 255);"> public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">override</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">WriteAttribute(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">name,</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">value,</span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);">encode)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> if</span><span style="color: rgb(0, 0, 0);">(_url</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">&&</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Compare(name,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">action</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)</span><br><span style="color: rgb(0, 0, 0);"> {</span><br><span style="color: rgb(0, 0, 0);"> value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">_url;</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"> base</span><span style="color: rgb(0, 0, 0);">.WriteAttribute(name,value,encode);</span><br><span style="color: rgb(0, 0, 0);"> }</span><br><span style="color: rgb(0, 0, 0);">}</span><br><span style="color: rgb(0, 0, 0);"></span></font></blockquote>
<font size="2"><span style="color: rgb(0, 0, 0);">}</span></font>
</div>
<font size="2"><br><br> 把这个文件编译成dll,并在你的项目中引用它。<br><br> 然后把项目中的所有aspx文件对应的cs文件中的继承page类的代码改写为继承OLPage。<br> 例如<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">WebForm1:page</span></font>
</div>
<font size="2"><br> 改写为<br></font>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="2"><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">WebForm1:URL.OLPage</span></font>
</div>
<font size="2"><br><br> 这样就解决回发问题。</font>
相关推荐
asp.net c# Url重写和无扩展名Url重写 内有所有源码 注:无扩展名Url重写,必须是虚拟目录的相对路径
URL重写URL重写URL重写URL重写URL重写URL重写
Url重写,无后缀Url重写,UrlRewriter.dll
URL重写URL重写URL重写URL重写URL重写URL重写
URL重写DEMOURL重写DEMOURL重写DEMOURL重写DEMO
C# url重写 C# url重写 C# url重写
描 述:UrlReWrite(Url重写或伪静态)完美示例源码 UrlReWrite(Url重写或伪静态)完美示例源码,已利用ActionlessForm解决原始地址form回传的问题 例如:/products.aspx?category=books 转换为/products/Books....
URL重写URL重写URL重写URL重写URL重写URL重写
IIS URL Rewrite模块(URL 重写)
URL重写
这是本人博客上《用自定义IHttpModule实现URL重写》一文的示例代码,如果有未尽之处或者不明白之处请到本人博客上查看,网址是:http://blog.csdn.net/zhoufoxcn/archive/2009/07/14/4346356.aspx
jsp 动态转静态 URL重写 jsp 动态转静态 URL重写 jsp 动态转静态 URL重写 jsp 动态转静态 URL重写
URL重写实例,无二级重写,URL重写实例,实例代码 vs2008
url重写工具 .net重写url的工具
URL重写的一个例子,不是自己的东东,有需要的自己下来看看
URL重写概念和例子:这是简单的URL重写概念和例子能使你容易的快速了解学习。
asp.net url重写 demo 框架 3.5 利用Intelligencia.UrlRewriter.dll组件实现url重写
iis7.5url重写安装包32和64,url重写,一键安装即可,
URL重写指南 - Apache HTTP服务器.mht
url重写软件配合iis服务器