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)
{
_url = HttpContext.Current.Request.RawUrl;
}
public override void WriteAttribute(string name, string value, bool encode)
{
if (_url != null && string.Compare(name, "action ", true) == 0)
{
value = _url;
}
base.WriteAttribute(name, value, encode);
}
}
internal class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter
{
private string _url;
internal FormFixerHtmlTextWriter(TextWriter writer):base(writer)
{
_url = HttpContext.Current.Request.RawUrl;
}
public override void WriteAttribute(string name, string value, bool encode)
{
if (_url != null && string.Compare(name, "action ", true) == 0)
{
value = _url;
}
base.WriteAttribute(name, value, encode);
}}}
熟悉urlrewrite的朋友,我相信都知道或看过上面这段代码,
url重写后,当点击一个按钮postback的时候,url会变成真实的url,如果用上面的代码写个page类,然后页面继承该类,就不会有问题了,我跟踪了一下,发现HtmlTextWriter一直是它被调用,Html32TextWriter好像没有调用(不知道我跟踪错了没有)小弟不明白的地方是这个类Html32TextWriter到底 跟HtmlTextWriter有什么差别,默认的page调用的是哪里呢?我看了msdn帮助也没有搞明白,请教大家了,谢谢
------解决方案--------------------------------------------------------
看了下msdn下Html32TextWriter好象主要是为了让页面呈现的内容能够向前兼容的作用.
另外调用方面msdn是这样说的:
ASP.NET Web 窗体通过检查 HttpBrowserCapabilities 类的 TagWriter 属性,自动对 HTML 3.2 和早期的浏览器使用此类。
------解决方案--------------------------------------------------------
应该是如果碰到老浏览器的话会用这个类,默认用HtmlTextWriter吧