|
最后就是让所有的页面都调用这个基类,修改一下Web.config就好了
<!-- Openlab.Controls.OLPage为页面基类,Openlab.Controls为基类所在dll -->
<pages pageBaseType="Openlab.Controls.OLPage, Openlab.Controls"/>
附页面基类完整代码(参考CS代码完成):
复制代码 代码如下:
using System;
using System.IO;
using System.Web;
using System.Web.UI;
namespace Openlab.Controls
...{
/**//// <summary>
/// 页面基类
/// </summary>
public class OLPage : Page
...{
public OLPage()
...{
}
Render#region Render
/**//// <summary>
/// 重写默认的HtmlTextWriter方法,修改form标记中的value属性,使其值为重写的URL而不是真实URL。
/// </summary>
/// <param name="writer"></param>
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);
}
#endregion
}
FormFixers#region FormFixers
FormFixerHtml32TextWriter#region FormFixerHtml32TextWriter
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)
...{
// 如果当前输出的属性为form标记的action属性,则将其值替换为重写后的虚假URL
if (_url != null && string.Compare(name, "action", true) == 0)
...{
value = _url;
}
base.WriteAttribute(name, value, encode);
}
}
#endregion
FormFixerHtmlTextWriter#region FormFixerHtmlTextWriter
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);
}
}
#endregion
#endregion
}
AspNet技术:asp.net url重写后页面回传问题,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。